谁能帮我看看这个程序!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/20 07:30:17
#include <stdio.h>
void main()
{
char str[20];
int i=0;
scanf("%s",str);

while(str[i]!='\0')
{
if(str[i]>'a'&&str[i]<'z')
str[1]=str[1]-32;
i++;
}
printf("%s",str);
getch();
}

要求是:从键盘上输入一个字符串,要求将每个单词的第一个字母转换成大写
为什么和要求的不一样呢?
应该怎么改.

#include <stdio.h>
void main()
{
char str[20];
int i=0;
scanf("%s",str);

while(str[i]!='\0')
{
if(str[i]>='a'&&str[i]<='z')
str[i]=str[i]-32;
i++;
}
printf("%s\n",str);
getchar();
}

不懂