cs50首字母pset2意外错误

时间:2016-09-24 00:08:33

标签: c if-statement cs50 isspace

当我尝试在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;
}

1 个答案:

答案 0 :(得分:0)

您的for()语法错误。那里只能有2个;个字符。如果要初始化多个变量,请将其与,分开,而不是;

for (i = 0, (n = strlen (name)); i < n; i++)
相关问题