您好,我正在尝试将第 3 个文件添加到下面的代码中,但我不知道如何执行此操作。
原代码:
char *fileOpen1;
char *fileOpen2;
while(fgets(line, 50, fr) != NULL)
{
if(count == 0)
{
fileOpen1 = "file1.pifz";
}
else
{
fileOpen2 = "file2.pifz";
}
count++;
printf("%s", line);
printf("%s", fileOpen1);
printf("%s", fileOpen2);
}
fclose(fr);
新的测试代码(没用)
char *fileOpen1;
char *fileOpen2;
char *fileOpen3;
while(fgets(line, 50, fr) != NULL)
{
if(count == 0)
{
fileOpen1 = "file1.pifz";
}
else if(count == 0)
{
fileOpen2 = "file2.pifz";
}
else
{
fileOpen3 = "file3.pifz";
}
count++;
printf("%s", line);
printf("%s", fileOpen1);
printf("%s", fileOpen2);
printf("%s", fileOpen3);
}
fclose(fr);
如果我使用(新测试代码)它会显示 file1 和 file3 两次,而不是 file1 > file2 > file3
imageString(im, black, 15, 160,253 , thePrograms[0].progName); //needs to be file1
imageString(im, black, 15, 160,303 , thePrograms[1].progName); //needs to be file2, but is file3
imageString(im, black, 15, 160,353 , thePrograms[2].progName); //needs to be file3
最佳答案
if(count==0)
{
// You're here if count is 0
}
else if(count==0)
{
// You're here if count isn't 0 and is 0
}
else
{
// You're here if count isn't 0
}
您不能进入第一个 else if
,因为您已经确定计数不为 0。
关于c - 如何用if函数打开3个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27787637/