Please I need help, I can't find my bug...
data.txt contains:
/* name surname integer integer */
name surname 011 111
name surname 1 2
...
then:
But it does not work! can anyone provide help?Code:#include <stdio.h> #include <string.h> #include <stdlib.h> struct person { char *name, *surname; int age, income; }; struct person *init(void) { struct person *p; p = (struct person *) malloc(sizeof(struct person)); p->name = NULL; p->surname = NULL; p->age = 0; p->income = 0; return p; } int main(void) { FILE *fp = fopen("data.txt", "r"); struct person *list[10]; /* no matter... */ int register i = 0; while (!feof(fp)) { list[i] = init(); fscanf(fp, "%s %s %d %d\n", list[i]->name, list[i]->surname, &(list[i]->age), &(list[i]->income)); i++; } fprintf("%s %s\n", list[0]->name, list[0]->surname); fclose(fp); return 0; }
Cheers
DBG



3Likes
LinkBack URL
About LinkBacks



