fopen giving error

infyanurag's Avatar, Join Date: Aug 2009
Newbie Member
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
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Try :

Code: C++
FILE *parafile;
parafile=fopen(parfilename,"rb");
if (parafile==NULL) {
printf("error");
}
0
infyanurag's Avatar, Join Date: Aug 2009
Newbie Member
Quote:
Originally Posted by SaswatPadhi View Post
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.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
> 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.