0

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

1 回答 1

0

你的for()语法是错误的。里面只能有2个;字符。如果要初始化多个变量,请用 分隔它们,,而不是;

for (i = 0, (n = strlen (name)); i < n; i++)
于 2016-09-24T00:13:29.967 回答