#include<ctype.h> |
|
20分 |
#include<ctype.h> #include<stdbool.h> #define STOP ""|"" int main() { char c; char prev; long n_chars; int n_lines; int n_words; int p_lines; bool inword; while (1) { n_chars = 0L; n_lines = 0; n_words = 0; p_lines = 0; inword = false; printf("Enter text to be analyzed(|to terminate,Ctrl+C to exit);\n"); prev = ""\n""; while ((c = getchar()) != STOP) { n_chars++; if (c == ""\n"") n_lines++; if (!isspace(c) && !inword) { inword = true; n_words++; } if (isspace(c) && inword) inword = false; prev = c; } if (prev != ""\n"") p_lines = 1; printf("characters=%ld,words=%d,lines=%d,", n_chars, n_words, n_lines); printf("partial lines=%d\n", p_lines); } return 0; } |
赵老师,请问实现ctrl+c退出是那一句,我觉得在输入ctrl+c以后第二个while虽然没实现但是第一个while条件仍然为真,应该会继续等待输入,而不是退出,请赵老师解答 |
|
赵老师,不好意思,我才查了吓知道ctrl+c是强制退出 |
|
ctrl+c有时候不行就用Ctrl+Break,如果还是不行,点cmd窗口右上角的×,如果还是不行,在任务管理器里面结束进程cmd.exe!
|