1

I'm having trouble with a piece of coding I'm working on. It involves linked lists and certain annoying pointers. Here is some sample code:

PersonType *person;
FILE *c;
c = fopen("file.csv", "r");
char in[100];
fgets(in, 80, c); //Edited

root->head->next = 0;
char *getNum = strtok(in, ";");
char *getName = strtok(NULL, ";");
char *getHome = strtok(NULL, ";");
strcpy(root->head->getNum, getNum);
strcpy(root->head->getName, getName);
strcpy(root->head->getHome, getHome);
person = root->head;
if(person != 0){
    while(person->next != 0){
        person=person->next;
    }
}
//DEGUG
printf("Successfully Made a Person NODE");

The code won't read from the file and I am completely stumped why. In the XCODE debugger/tracer it initializes all the get chars with nil. Can someone please point me in the right direction?

Thanks.

EXAMPLE FILE

P1;Elyza;45 Random RD
P2;Ian;78 Shark CL
4

2 回答 2

1
c = fopen("file.csv", "r");
char in[100];
fgets(in, 80, cin);

你可能是说

c = fopen("file.csv", "r");
char in[100];
fgets(in, 80, c);  // <---

还要确保检查返回值fopen()以处理找不到文件的情况。

于 2013-05-15T11:23:58.117 回答
0
fgets(in, 80, cin);

有你的问题。
您肯定是要从以下内容中阅读FILE* c

fgets(in, 80, c);
于 2013-05-15T11:24:20.727 回答