I don't know why this code is wrong. Here's the code.
...
int main(void)
{
tof type;
char FileName[260];
printf("enter a file's name; you want to know size of this file(Maximum 260 character)\n");
fgets(FileName,sizeof(FileName),stdin);
Eliminate(FileName,'\n'); /*Eliminate '\n' Because '\n' remain in FileName*/
printf("If the file's type is text, enter 1, It is binary, enter 2");
scanf("%d",&type);
if(type != Text && type != Binary)
return -1;
else if(type == Binary)
FILE * fp = fopen(FileName,"rb");
else if(type == Text)
FILE * fp = fopen(FileName,"rt");
long FileSize = SOF(fp,type);
if(FileSize < 0)
printf("It exceeded the limit It can calculate(about over 2GB)");
else
printf("Size of the file is %d byte.",FileSize);
fclose(fp);
return 0;
}
int SOF(FILE * subject,const tof File_type)
{
long InitPos = ftell(subject);
fseek(subject,0,SEEK_SET);
long Bite = 0;
int * Buf; //Called Buf due to fread function, little meaning
if(File_type == Text) {
while(fgetc(subject) != EOF && Bite >= 0)
//When "Bite" exceed Maximum value of long type, return negative
{
Bite++;
}
}
else if(File_type == Binary) {
while(fread((void*)Buf,1,1,subject) == 1 && Bite >= 0) {
Bite++;
}
}
fseek(subject,InitPos,SEEK_SET);
return Bite;
}
...
('SOF' retunrns with a size of a file, 'Eliminate' is the function which eliminates some charater in some string, 'Text' and 'Binary' is declared to 1 and 2 with using enum)
The error message the compiler shows is:
'fp' was not decleared in this scope
But
if(type != Text && type != Binary)
return -1;
else if(type == Binary)
FILE * fp = fopen(FileName,"rb");
else if(type == Text)
FILE * fp = fopen(FileName,"rt");
This code contains the declaration of FILE pointer 'fp' apparently as you can see.
Why did this error appear?
main()
function and at least one#include
. It's also not minimal - there's much in there that's irrelevant to your problem. Please edit your code so it's a minimal reproducible example of your problem (including any necessary inputs, but preferably not needing any), then we can try to reproduce and solve it. You should also read How to Ask.