~eaglescreen/ple/2010-2011

« back to all changes in this revision

Viewing changes to RAFAEL BELMONTE 2da EVALUACION/structs/04_punteros_a_structs.c

  • Committer: Rafael Belmonte
  • Date: 2011-03-07 11:29:26 UTC
  • Revision ID: eaglescreen@gmail.com-20110307112926-g1lt1b5i0sl9j1mk
Actualizacion mayor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <stdio.h>
 
3
#include <conio.h>
 
4
#define N_LIBROS 3
 
5
#define MAXTIT 41
 
6
#define MAXAUT 31
 
7
#define MAXAUX 8
 
8
 
 
9
typedef struct 
 
10
{
 
11
        char titulo[MAXTIT];
 
12
        char autor[MAXAUT];
 
13
        float precio;
 
14
} biblio;
 
15
 
 
16
int main()
 
17
{
 
18
        unsigned i;
 
19
        char aux[MAXAUX];
 
20
        biblio libros[N_LIBROS];
 
21
        biblio *ptrLibros=libros;
 
22
        for (i=0;i<N_LIBROS;i++)
 
23
        {
 
24
                printf("\nDame un titulo: ");
 
25
                ptrLibros[i].titulo[0]=MAXTIT-2;
 
26
                cgets(ptrLibros[i].titulo);
 
27
                printf("\nDame el autor del libro: ");
 
28
                ptrLibros[i].autor[0]=MAXAUT-2;
 
29
                cgets(ptrLibros[i].autor);
 
30
                printf("\nDame el precio del libro: ");
 
31
                aux[0]=MAXAUX-2;
 
32
                ptrLibros[i].precio=atof(cgets(aux));
 
33
        }
 
34
        printf("\nLos datos introducidos son los siguientes: ");
 
35
        for (i=0;i<N_LIBROS;i++)
 
36
        {
 
37
        printf("\n\t    LIBRO %d: \n",i+1);
 
38
        printf("\n\t    Titulo: %s \n\t    Autor: %s \n\t    Precio: %.2f\n", &ptrLibros[i].titulo[2],&ptrLibros[i].autor[2],ptrLibros[i].precio);
 
39
        }
 
40
        getch();
 
41
        clrscr();
 
42
        return 0;
 
43
}