Author Topic: BUILD .EXE FILE NOT OPENING ONLY FOR FILE I/O IN C  (Read 3702 times)

Offline gautam736

  • Single posting newcomer
  • *
  • Posts: 2
BUILD .EXE FILE NOT OPENING ONLY FOR FILE I/O IN C
« 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();
}


Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: BUILD .EXE FILE NOT OPENING ONLY FOR FILE I/O IN C
« Reply #1 on: May 30, 2011, 09:17:33 pm »
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ