News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

BUILD .EXE FILE NOT OPENING ONLY FOR FILE I/O IN C

Started by gautam736, May 30, 2011, 11:15:43 AM

Previous topic - Next topic

gautam736

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();
}


MortenMacFly

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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]