- int main(int argc, const char * argv[]) {
- int count =0;
- char arr[100];
- int words=0;
- printf("请输入字符串:\n");
- gets(arr);
- // puts(arr);
- for (int i=0; arr[i]!='\0'; i++) {
- if (arr[i]== ' '){
- words =0;
- }else if(words == 0){
- arr[i]=arr[i]-32;
- count++;
- words =1;
-
- }
- }
- printf("一共%d个单词,改写后的字符串:%s\n",count,arr);
-
-
- return 0;
- }
复制代码
|