当前位置: 动力学知识库 > 问答 > 编程问答 >

c - error: 'else' without a previous if

问题描述:

I am getting a error: 'else' without a previous if when i'm compiling using gcc on this bit of code:

while(fgets(line, 50, fr) != NULL)

{

if(count == 0)

{

fileOpen1 = "pro1.pifz";

}

else

{

fileOpen2 = "pro2.pifz";

}

else

{

fileOpen2 = "pro3.pifz";

}

count++;

printf("%s", line);

printf("%s", fileOpen1);

printf("%s", fileOpen2);

printf("%s", fileOpen3);

}

fclose(fr);

The error come when i add the second else function. Is there a simple way of fixing this error?

Many thanks

网友答案:

You may not use two else statements one after another in if statement. The if statement may have only one else statement.

else
{
    fileOpen2 = "pro2.pifz";
}
else
{
    fileOpen2 
}

You could write for example instead

else if ( /* some condition */ )
{
    fileOpen2 = "pro2.pifz";
}
else
{
    fileOpen2 
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: