Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: gautam736 on May 30, 2011, 11:15:43 am
-
Every programms are running but only file input output build .exe file is not opening though file programs are compiling and running without errors.
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *f;
char ch;
f=fopen("op.DAT","r");
while(ch!=EOF)
{
ch=fgetc(f);
printf("%c",ch);
}
getch();
}
-
You do several things wrong:
- You don't verify the file exist,
- You don't verify you got a valid file pointer after fopen
- You most likely didn't put the file "op.DAT" in the working directory of you application which you setup in the project options.
- If you are on Linux: you need to check the file's name as it is case sensitive (a capital letter extension is very un-common on such platforms)
- You said nothing about your build environment -> platform (OS), version etc...
Fixing all this will probably make you app working.
BTW: As this is not related to Code::Blocks, but a general programming question I am locking the topic now.