《c程序设计语言》读书笔记--首次输入不能是空符;最多10个字符
#include <stdio.h> #define Num 10 int main() { int wor = 0; int arr[Num] = {0}; int c,count = 0,i; int flag = 0; printf("Please input at most 10 words.\n"); while((c = getchar()) != EOF) { if(c == '\n' ||c == ' ' || c == '\t') { if(flag == 0) { arr[count] = wor; count++; wor = 0; flag = 1; } } else { flag = 0; wor++; } } for(i = 0;i < count;i++) printf("%d ",arr[i]); return 0; } 两个问题:首次输入不能是空符;最多10个字符。以后解决 。