/* * Archivo: TPersona.h * Autor: J. Miguel Guanira E. * * Created on 7 de octubre de 2011, 03:25 PM */ #ifndef TPERSONA_H #define TPERSONA_H struct TPersona { char codigo[15]; char *nombre; int dni; char direccion[50]; double sueldo; }; #endif /* TPERSONA_H */ /* * Archivo: leeStruct.h * Autor: J. Miguel Guanira E. * * Created on 7 de octubre de 2011, 03:26 PM */ #ifndef LEESTRUCT_H #define LEESTRUCT_H #include "TPersona.h" TPersona leeStruct(void); #endif /* LEESTRUCT_H */ /* * Archivo: leeStruct.cpp * Autor: J. Miguel Guanira E. * * Created on 7 de octubre de 2011, 03:26 PM */ #include #include #include "TPersona.h" TPersona leeStruct(void){ TPersona dato; char aux[100]; printf("Ingrese los datos del empleado:\n"); printf("Codigo : "); gets(dato.codigo); printf("Nombre : "); gets(aux); dato.nombre = new char[strlen(aux)+1]; strcpy(dato.nombre, aux); printf("DNI : "); scanf("%d", &dato.dni); while(getchar()!='\n'); printf("Direccion: "); gets(dato.direccion); printf("Sueldo : "); scanf("%lf", &dato.sueldo);while(getchar()!='\n'); return dato; } /* * archivo: main.cpp * Autor: J. Miguel Guanira E. * * Created on 7 de octubre de 2011, 03:24 PM */ #include #include #include "TPersona.h" #include "leeStruct.h" int main(void) { TPersona empleado; empleado = leeStruct(); printf("\n\nDatos leidos en empleado:\n"); printf("Codigo : %s\n", empleado.codigo); printf("Nombre : %s\n", empleado.nombre); printf("DNI : %d\n", empleado.dni); printf("Direccion: %s\n", empleado.direccion); printf("Sueldo : %10.2f\n", empleado.sueldo); return (EXIT_SUCCESS); }