/*输入一行英文文本,将每一个单词的第一个字母变成大写。例如:输入"This is a C program.",输出为"This is A C Program."*/#include <string.h>#include <stdio.h>#include <ctype.h>void fun(char *p) {int k = 0;while (*p ) //非0{if (k == 0 && *p != ' ')//单词首字母{*p = toupper(*p);//c库函数 把小写字母转换为大写字母k = 1;} else if (*p != ' ')k = 1;elsek = 0;*p++;}}int main() {char str[81];printf("please input a English text line:");gets(str);printf("The original text line is :");puts(str);fun(str);printf("The new text line is :");puts(str);return 0;}
运行结果