一个c语言的问题:首字母变大写输入一个英文句子,将每个单词的第一个字母改成大写字母.如 input:i like it output:I Like It我的代码#includevoid main(){\x09char str[100],*p;\x09while(scanf("%s",str)!=EOF)\x09{\x09p=s

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 20:02:27

一个c语言的问题:首字母变大写输入一个英文句子,将每个单词的第一个字母改成大写字母.如 input:i like it output:I Like It我的代码#includevoid main(){\x09char str[100],*p;\x09while(scanf("%s",str)!=EOF)\x09{\x09p=s
一个c语言的问题:首字母变大写
输入一个英文句子,将每个单词的第一个字母改成大写字母.如
input:i like it
output:I Like It
我的代码
#include
void main()
{\x09char str[100],*p;
\x09while(scanf("%s",str)!=EOF)
\x09{\x09p=str;
\x09\x09*p=*p-32;
\x09\x09for(p=str+1;*p!='\0';p++)
\x09\x09{\x09
\x09\x09\x09if(*p=' ')\x09
\x09\x09\x09{\x09*(p+1)=*(p+1)-32;
\x09\x09\x09}
\x09\x09}
printf("%s\n",str);
\x09}
}

一个c语言的问题:首字母变大写输入一个英文句子,将每个单词的第一个字母改成大写字母.如 input:i like it output:I Like It我的代码#includevoid main(){\x09char str[100],*p;\x09while(scanf("%s",str)!=EOF)\x09{\x09p=s
#include
#include
void main()
{
char str[100],*p;
while(gets(str)!=EOF)
{p=str;
*p=toupper(*p);
for(p=str+1;*p!='\0';p++)
{
if(*(p-1)==' ')
{
*p=toupper(*p);
}
}
printf("%s\n",str);
}
}