【发布时间】:2013-11-18 00:55:14
【问题描述】:
我想将输入字符串的每个单词的首字母大写。
这就是我所做的(还没有工作)
void main() {
char sentence[100];
int i;
printf("Enter your name and surnames: ");
gets(sentence);
for(i = 0; i<strlen(sentence); i++){
if(sentence[i] == ' '){
printf("%c", toupper(sentence[i]+1));
//I want to advance to next item respect to space and capitalize it
//But it doesn't work
} else {
printf("%c", sentence[i]);
}
}
}
输入:james cameron
希望输出:詹姆斯·卡梅隆
【问题讨论】:
-
gets()的使用风格极差。无法安全使用,已在最新版C标准中删除。 -
有趣的是,3小时前也有人问过同样的问题:stackoverflow.com/questions/20036553/…
-
另外:包括相关的头文件
#include <stdio.h> #include <string.h> #include <ctype.h>,如果你不做坏事可能会发生 -
@MitchWheat -
inspace()你的意思是isspace()?
标签: c capitalization