HI , I have a basic question to ask.
how do i open a .txt file in C ? i am using the code shown below which is always telling that "file not found".

#include <stdio.h>
main()
{
            FILE*fp ;

            fp = fopen ( "PR1.txt","r" ) ;
            if( fp == NULL )
            {
                    puts ( "file not found " ) ;

                    return 0;
            }
}

the file PRI.txt is placed in borland turbo c++ directory. is it the right directory for file processing ?
thanks in advance.

No. It needs to be in the project directory -- where the .EXE lives.

Using puts() -- BRAVO!!! Finally someone who doesn't use printf() :o)

Using main() -- Oops. main() is an int. Always.

Using puts() -- BRAVO!!! Finally someone who doesn't use printf() :o)

I think you are a good C programmer. A few persons are using puts in their code, but puts performance is better than printf.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.