我在C编程语言中遇到了一些问题。这是目前的问题。我必须读取格式如下的文件:将文件读入C中的链接列表中
q 99
z 8
q 4
每行以q或z开头,后跟一个制表符,后跟一个数字。我只想将第q行开始的数字存储在链接列表中。
我能够隔离以q开头的行,但是我的代码将值99分隔为两个单独的节点9和9.我不知道如何解决此问题。
任何建设性的帮助将是伟大的,善良,我是新的C语言!
// Beginning of code reads the file in, and provides structure and
// function declarations
struct node *start = NULL;
char w;
while((w = fgetc(filep))!= EOF) //filep is pointer to the file
{
if(w=='z')
break;
else if(isdigit(w))
push(&start, w); //push function creates the nodes
}
// rest of code has function definitions of push and print, creating
// and printing the linked list
这是因为你得到*单个字符*。我建议你阅读['fgets'](http://en.cppreference.com/w/c/io/fgets)和['sscanf'](http://en.cppreference.com/w/c/io/fscanf), – 2015-02-08 00:20:02
'char w;' - >>'int w;'...一开始.. – wildplasser 2015-02-08 00:30:23