C语言:将每个单词中的第一个字母改成大写字母
【独立编程】程序功能:输入一行字符串,将每个单词中的第一个字母改成大写字母(如果已经是大写则不变)。例如,输入 I am a student,输出 I Am A Student。#include <stdio.h>#include <string.h>int main() {char s[80];printf("Input a strings:");//scanf中输入字符
·
【独立编程】程序功能:输入一行字符串,将每个单词中的第一个字母改成大写字母(如果已经是大写则不变)。例如,输入 I am a student,输出 I Am A Student。
#include <stdio.h>
#include <string.h>
int main() {
char s[80];
printf("Input a strings:");
//scanf中输入字符串是以空格为结束的,所以不能用scanf
gets(s);
int j;
int i = 1;
if (s[0] != ' ' && s[0] >= 'a')
s[0] = s[0] - 32;
while (s[i] != '\0') {
if (s[i - 1] == ' ' && s[i - 1] >= 'a') {
s[i] = s[i] - 32;
}
i++;
}
printf("%s", s);
return 0;
}
更多推荐
已为社区贡献1条内容
所有评论(0)