Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   fopen giving error (http://www.go4expert.com/forums/fopen-giving-error-t18807/)

infyanurag 4Aug2009 14:01

fopen giving error
 
Hi all

I am trying to open a .par file with the help of fopen but the file is not getting opened.
parfilename is passed as an argument to this, the value is domcol.par.
The domco..par is resiging in same path as the code.

FILE *parafile;
parafile=fopen(parfilename,"rb");
if (!parafile) {
printf("error");
}

I am geeting error.
kindly let me know as how to proceed with this.

Thanks
Anurag

SaswatPadhi 4Aug2009 19:05

Re: fopen giving error
 
Try :

Code: C++

FILE *parafile;
parafile=fopen(parfilename,"rb");
if (parafile==NULL) {
printf("error");
}


infyanurag 5Aug2009 11:10

Re: fopen giving error
 
Quote:

Originally Posted by SaswatPadhi (Post 54207)
Try :


Code: C++
</p>
<p>FILE *parafile;</p>
<p>parafile=fopen(parfilename,"rb");</p>
<p>if (parafile==NULL) {</p>
<p>printf("error");</p>
<p>}</p>
<p>

I am getting error as output.
But why?
parfilename is domcol.par and i could see that.

xpi0t0s 9Aug2009 00:52

Re: fopen giving error
 
> The domco..par is resiging in same path as the code.

OK, but is the file in the current directory, i.e. where you are now? A NULL return from fopen usually means the file can't be found. If it's not in the current directory then you need to include the full path to the file, and if it's in the same directory as the file then you can get the location from argv[0].

Saswat: if (!parafile) and if (parafile==NULL) are equivalent.


All times are GMT +5.5. The time now is 05:54.