cs50首字母pset2意外错误(cs50 initials pset2 unexpected error)
当我尝试在for循环中使用“i <n”时,出现错误(准确地说是4)。 如果我把它拿出来,我会得到一个无限循环。 我也似乎无法得到if语句运行。 关于我可以改进的任何想法?
int main() { int i; int n; //Program to get the user's name and reply with their capitalized initials { //Ask user for their name printf("What is your full name?\n"); } //look for 1st character of each part of name given string name = GetString(); for (i = 0; (n = strlen (name)); i < n; i++) { printf("Your intitals are %c", toupper(name[0])); { if (isspace(name[i])) { printf("%c", toupper(name[i+1])); } printf("!\n"); } } return 0; }I am getting an error (4, to be precise) when I try to use "i < n" in my for loop. If I take it out, I get an infinite loop. I also can't seem to get the if statement to run. Any thoughts on what I can improve?
int main() { int i; int n; //Program to get the user's name and reply with their capitalized initials { //Ask user for their name printf("What is your full name?\n"); } //look for 1st character of each part of name given string name = GetString(); for (i = 0; (n = strlen (name)); i < n; i++) { printf("Your intitals are %c", toupper(name[0])); { if (isspace(name[i])) { printf("%c", toupper(name[i+1])); } printf("!\n"); } } return 0; }最满意答案
你的for()语法是错误的。 只能有2个; 那里的人物。 如果要初始化多个变量,请将它们分隔开,而不是; 。
for (i = 0, (n = strlen (name)); i < n; i++)Your for() syntax is wrong. There can only be 2 ; characters in there. If you want to initialize multiple variables, separate them with ,, not ;.
for (i = 0, (n = strlen (name)); i < n; i++)更多推荐
发布评论