fopen giving error

Newbie Member
4Aug2009,14:01   #1
infyanurag's Avatar
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ЯИ Τ0 С0δЭ ~
4Aug2009,19:05   #2
SaswatPadhi's Avatar
Try :

Code: C++
FILE *parafile;
parafile=fopen(parfilename,"rb");
if (parafile==NULL) {
printf("error");
}
Newbie Member
5Aug2009,11:10   #3
infyanurag's Avatar
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.
Mentor
9Aug2009,00:52   #4
xpi0t0s's Avatar
> 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.