【独立编程】程序功能:输入一行字符串,将每个单词中的第一个字母改成大写字母(如果已经是大写则不变)。例如,输入 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;
}
Logo

助力广东及东莞地区开发者,代码托管、在线学习与竞赛、技术交流与分享、资源共享、职业发展,成为松山湖开发者首选的工作与学习平台

更多推荐