/** * escribo.c * * @descripcion escribe estructuras del tipo registro a un fichero */ #include #include /* registro */ struct registro { int edad; char nombre[60]; }; int main() { int i; FILE *f; struct registro r; /* creamos 3 registros */ f=fopen("registros.dat","w"); if (!f) { return 1; } for (i=1;i<=3; i++) { switch(i) { case 1: r.edad=23; strcpy(r.nombre,"R-Ratones"); break; case 2: r.edad=1000; strcpy(r.nombre,"Mun-ra"); break; case 3: r.edad=9; strcpy(r.nombre,"bart"); break; default: break; } fwrite(&r,sizeof(struct registro),1,f); } fclose(f); printf("Datos fueron creados\n"); return 0; }