读入一个单词,为什么输入“ 和ctrl+z”时,没有直接退出程序
#include <stdio.h>
#define LEN 80
char * getword(char * str);
int main(void)
{
char input[LEN];
while (getword(input) != NULL)
puts(input);
puts("Done.\n");
return 0;
}
#include <ctype.h>
C Primer Plus Sixth Edition Programming Exercise Selected Answers
25
char * getword(char * str)
{
int ch;
char * orig = str;
// skip over initial whitespace
while ((ch = getchar()) != EOF && isspace(ch))
continue;
if (ch == EOF)
return NULL;
else
*str++ = ch; // first character in word
// get rest of word
while ((ch = getchar()) != EOF && !isspace(ch))
*str++ = ch;
*str = '\0';
if (ch == EOF)
return NULL;
else
{
while (ch != '\n')
ch = getchar();
return orig;
}
}
为什么输入空格和结束符时没有结束程序
qq_45266983
2021/01/14 00:06- c语言
- 点赞
- 收藏
- 回答