c语言程序题:编成程实现输入一串英文字母,要求将每个单词首字母改成大写字母并输出
发布网友
发布时间:2022-05-18 13:26
我来回答
共2个回答
热心网友
时间:2023-10-17 06:38
#include <stdio.h>
#include <conio.h>
main()
{
char str[100] = {0};
printf( "input:\n" );
scanf( "%s",str );
int i = 0;
if( str[0]>='a' && str[0]<='z' ) str[0]=str[0]-'a'+'A';
while( str[i] != '\0' )
{
if( str[i] == ' ' )
{
if( str[i+1]>='a' && str[i+1]<='z' )
{
str[i+1]=str[i+1]-'a'+'A';
i++;
}
}
}
}
热心网友
时间:2023-10-17 06:38
忘了输出,补上
#include <stdio.h>
#include <conio.h>
main()
{
char str[100] = {0};
printf( "input:\n" );
scanf( "%s",str );
int i = 0;
if( str[0]>='a' && str[0]<='z' ) str[0]=str[0]-'a'+'A';
while( str[i] != '\0' )
{
if( str[i] == ' ' )
{
if( str[i+1]>='a' && str[i+1]<='z' )
{
str[i+1]=str[i+1]-'a'+'A';
i++;
}
}
}
printf( "\n%s\n",str );
getch();
}