文章
18
粉丝
0
获赞
3
访问
10.8k
#include<stdio.h>
#include<stdlib.h>
int main() {
char ch;
int count, length ;
while((ch = getchar()) != EOF){
char* s = (char*)malloc(sizeof(char)*1000);
count = 0;
length = 0;
while (ch != '\n'){
s[length++] = ch;
ch = getchar();
}
s[length] = '\0';
for (int i = 0; i < length; i++) {
if (s[i] == ' ' || s[i] == '.') {
if (s[i - 1] != ' '&& s[i - 1] != '.') {
printf("%d ", count);
count = 0;
}
}
else
count++;
}
printf("\n");
free(s);
}
}
在本地运行感觉没有错误,求指点
登录后发布评论
建议不要用getchar()输入,用gets或者scanf输入