|
发表于 2024-1-6 17:33:06
|
显示全部楼层
- #include<stdio.h>
- #include<ctype.h>
- #include<string.h>
- int main(int argc, const char *argv[])
- {
- char str[100];
- fgets(str, 100, stdin);
- // replace \n added by the fgets with \0
- str[strcspn(str,"\n")] = '\0';
- int i,m,n;
- m=1;
- for(i=0;str[i]!='\0';i++)
- {
- // if space then increase word count
- if(str[i] == ' ')
- {
- m++;
- // convert next character to uppercase
- if(str[i+1] != '\0'){
- str[i+1] = toupper(str[i+1]);
- }
- }
- // convert first character of string to uppercase
- if(i == 0){
- str[0] = toupper(str[0]);
- }
- }
- printf("%d\n",m);
- printf("%s\n",str);
- return 0;
- }
复制代码 |
|