[求助]用fgetc()读取文件时遇到的问题~~请帮帮我~~
文件input.txtToday is sunday. Our beautiful pools had turned brownish green!
Needless to say, for the rest of the weekend, we had to stay indoor watching even the sillest TV.
[bo]output
======
Today
is
sunday
.
Our
。。。。。(省略)
say
,
TV
.[/bo]
我要读取文件中的字符串为一个word node,逗号和句号也本别为一个word node.
读取字符串为一个word node没问题,怎样把 逗号(,)和句号(.)也变成一个word node
我的链表没问题,所以我只贴有问题的部分
int i, counter = 1, found = 0;
char ch, *word;
FILE* fp;
while(!feof(fp))
{
i = 0;
word = malloc(sizeof(char) * SIZE);
while((ch = fgetc(fp)) != EOF)
{
if(isalpha((int)ch))
{
word[i++] = ch;
}
else
{
// 如果我在这写if(ch == ',' || ch == '.')word[i++] = ch;结果会显示成字符串和符号成为一个node
word[i] = '\0';
if(i)
break;
}
}
if(*word == '\0')
break;
counter++;
。。。。。省略。。。。。。
}
非常感谢~~~~