所以我想创建一个代码,将字符串数组中每个单词的首字母大写,然后以相反的顺序输出字符串。我无法反向打印数组,但除此之外,这就是我想出的:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char string[100];
int i, j;
char newString[100];
printf("\nEnter string: ");
gets(string);
for (i=0; i <strlen(string); i++){
if (string[i] == ' ' && isalnum(string[i+1])==1){ //if the character is preceded by a space
newString[i] = toupper(string[i+1]); //copy the uppercase of the character to newString
}
if (isalpha(string[0]) == 1){ //capitalize the first character in the string if it is a letter
newString[0] = toupper(string[0]); //copy character to newString
}else{
newString[i] = string[i];
}
}
printf("%s", newString); //preferably, the newString should be printed in reverse order, but I can't seem to do it.
}
如果:
输入: curran lennart
此代码的假定输出:Curran Lennart
(我想要的:narruC tranneL)
事实上,我得到的只是以下输出:
curran lennarta
输入“kate daniels”返回“kate daniels”。如果输入是:
julie olsen
输出是:
julie olsenw
请帮忙。:(