How I can write (or read) on a fich an int??
I want to write (or read) in to the fich "int numero"
Code:
struct contfich{
char nombre[100];
char apellidos [100];
int numero;
char telefono[10];
};
struct contlist{
char nombre[100];
char apellidos [100];
int numero;
char telefono[10];
struct contlist *sig;
};
Code:
void insertarlista(struct contlist**plista, struct contfich c){
struct contlist *nuevo;
nuevo=(struct contlist*)malloc(sizeof(struct contlist));
strcpy((*nuevo).nombre, c.nombre);
strcpy((*nuevo).apellidos, c.apellidos);
strcpy((*nuevo).telefono, c.telefono);
nuevo->sig=*plista;
*plista=nuevo;
}
void guardarlista (struct contlist * lista){
FILE*fich;
char nombrefich[100];
struct contlist *aux;
struct contfich c;
printf("Introduce nombre de la lista: ");
scanf("%s", nombrefich);
fich=fopen(nombrefich, "wb");
aux=lista;
while(aux!=NULL){
strcpy(c.nombre, aux->nombre);
strcpy(c.apellidos, aux->apellidos);
strcpy(c.telefono, aux->telefono);
fwrite(&c,sizeof(struct contfich),1,fich);
aux=aux->sig;
}
fclose(fich);
printf("\nLista '%s' guardada!!\n\n", nombrefich);
system("PAUSE");
}