TranscendArcu
- 277
- 0
Code:
typedef struct
{
char firstname[MAXLEN];
char lastname[MAXLEN];
char color[MAXLEN];
char baseball[MAXLEN];
char skiing[MAXLEN];
char tree[MAXLEN];
int zipcode;
} student_t;
So this is a user defined structure that is supposed to store data about a person. It stores the first name, the last name, the favorite color, baseball preferences, skiing preferences, favorite tree, and the zipcode.
Code:
int scanstudents()
{
student_t scanstudent;
FILE *afile;
afile = fopen("FaceBlitz.txt","r");
fscanf(afile,"%s%s%s%s%s%s%d",&scanstudent.firstname,&scanstudent.lastname,&scanstudent.color,&scanstudent.baseball,&scanstudent.skiing,&scanstudent.tree,&scanstudent.zipcode);
printf("%s %s %s %s %s %s %d",scanstudent.firstname,scanstudent.lastname,scanstudent.color,scanstudent.baseball,scanstudent.skiing,scanstudent.tree,scanstudent.zipcode);
fclose(afile);
return (0);
}
When I scan through the file containing all of this information, I seem to do pretty well except that instead of scanning the zipcode, I just end up with a "0" being printed out. That's not even the right number of digits. My other scans seems to do just fine, but not the zipcode scan. Advice?