该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
文件input.txt
Today 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.
output
======
Today
is
sunday
.
\n
\n
Our
。。。。。(省略)
say
,
TV
.
我要读取文件中的字符串为一个word node,逗号,新一行和句号也本别为一个word node.
读取字符串为一个word node没问题,怎样把 逗号(,),新一行(\n)和句号(.)也变成一个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 == '.'|| ch == '\n')word[i++] = ch;结果会显示成字符串和符号成为一个node
word[i] = '\0';
if(i)
break;
}
}
if(*word == '\0')
break;
counter++;
。。。。。省略。。。。。。
}
非常感谢~~~~