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;
}
您的 for()
语法错误。那里只能有 2 ;
个字符。如果要初始化多个变量,用,
隔开,而不是;
.
for (i = 0, (n = strlen (name)); i < n; i++)
当我尝试在 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;
}
您的 for()
语法错误。那里只能有 2 ;
个字符。如果要初始化多个变量,用,
隔开,而不是;
.
for (i = 0, (n = strlen (name)); i < n; i++)