cs50首字母pset2意外错误(cs50 initials pset2 unexpected error)

编程入门 行业动态 更新时间:2024-10-25 06:34:01
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++)

更多推荐

本文发布于:2023-07-22 18:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首字母   意外   错误   unexpected   initials

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!