Hello,
In the project I'm currently working on, I'm trying to fill up an array of structures from stdin. The input contains names, and I want to put each name into an array of structures. Each structure has a name and an int associated with it. Here is what I have:
When I try to compile this, it says there is a parse error before the first { in the lines with people[pos] on it. I'm not entirely sure how to insert an entry into the array of structures. Can someone help me?Code:#include <stdio.h> #include <string.h> #define MAX_PERSON 100 struct person { char* name; int num; }; main(int argc, char *argv[]) { char buf[BUFSIZ]; char *tok; int lineNum = 1; int pos = 0; FILE *fp; char *names[MAX_PERSON]; struct person people[MAX_PERSON]; while ( fgets(buf,BUFSIZ,stdin) != NULL ) { tok = strtok(buf," "); people[pos] = {tok,lineNum}; pos++; tok = strtok(NULL,"\n"); people[pos] = {tok,lineNum}; pos++; lineNum++; } }



LinkBack URL
About LinkBacks


