【发布时间】:2015-02-08 00:13:23
【问题描述】:
我在使用 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
【问题讨论】:
标签: c file linked-list