我试图根据文件中的行数,在 if-else 语句中给出 Char 数组的大小。但是当我在之后尝试使用它时,会出现错误:"数组未声明"
FILE *f=fopen("G:\\workspaceC\\small1.txt","r");
while((c=fgetc(f))!=EOF)
{
if(c=='\n')
no_of_lines++;
}
printf("no_of_lines: %d",no_of_lines);
int fclose(FILE *f);
if(no_of_lines<10){
char b[30];
}
else if(no_of_lines>10 && no_of_lines<15){
char b[60];
}
else{
char b[106];
}
for(z=0;z<size;z++)
{
if(c==b[z]) ///////Here it gives error: "b undeclared"
{
flag=1;
break;
}
}
fclose()
——因为#include <stdio.h>
已经声明了它,所以你不需要这样做——而是直接调用它来关闭文件。 - Jonathan Lefflerint fclose(FILE *f);
-->fclose(f);
- BLUEPIXY