#include #include //Archivos con struct int main() { struct datos { char nombre[21]; int edad; char ciudad[21]; }persona; FILE *fichero; int i; fichero = fopen("gente.txt", "wt"); if (fichero == NULL) printf("No se pudo abrir el archivo.\n"); else { puts("Nombre:"); gets(persona.nombre); fprintf(fichero, "%s ", persona.nombre); puts("Edad:"); scanf("%d", &persona.edad); getchar(); fprintf(fichero, "%d ", persona.edad); puts("Ciudad:"); gets(persona.ciudad); fputs(persona.ciudad, fichero); fclose(fichero); } fichero = fopen("gente.dat", "rt"); if (fichero == NULL) printf("No se pudo abrir el archivo.\n"); else { while (!feof(fichero)) // while (feof(fichero) == 0) { fgets(persona.nombre, 60, fichero); puts(persona.nombre); fscanf(fichero, "%d", &persona.edad); getchar(); printf("%d", persona.edad); fgets(persona.ciudad, 60, fichero); puts(persona.ciudad); } fclose(fichero); } return 0; }