I'm trying to write a program,in which after pressing the 'v' button on the keyboard it opens a file for reading, and after pressing 'k' it closes the file and also ends the program.
(There will be more functions in the program, which will individually use the opened file, so it needs to remain open [I know it's a dumb way to design the program, but it's a homework with these rules]).
However, if I want to close the program in the same function main it was opened, but not in the same place, it gives me an error messagae fclose(fr)-fr is not unidentified
Can anyone help me?
Here is my code :
int main()
{
char c;
while(1){
scanf("%c",&c);
if(c == 'v'){
FILE *fr;
fr = fopen("D:\\Programming\\C\\Projekt\\Projekt 1\\pacienti.txt","r");
v();
}
else if(c == 'k'){
fclose(fr);
return 0;
}
}
}
FILE *fr;must be moved before thewhileloop. Probably v needs to get fr in arg ? - brunofris not identified because its not in scope ofelse if- IrAM