Hi y'all, I'm new to C and to this community so kindly bear with me.

I need to open a txt file using C(only).The thing is I'm able to open it if it is directly inside a drive partition(D:\), but if it is inside a folder then its not opening.

Here's my code:

/* directly inside drive D:\ */

fp1=fopen("/cygdrive/d/profile.txt","r");
  while (feof(fp1)==0)
   {
     fscanf(fp1,"%f %f",&inlet_a[1],&outlet_a[1]);
   }
    fclose(fp1);



/* inside a folder in drive D:\ */


    fp1=fopen("/cygdrive/d/NACA2412/profile.txt","r");
  while (feof(fp1)==0)
   {
     fscanf(fp1,"%f %f",&inlet_a[1],&outlet_a[1]);
   }
    fclose(fp1);

P.S: I'm using netbeans 6.9.1

Are you using the proper folder delimiter for your operating system?

Are you using the proper folder delimiter for your operating system?

I guess, like i said i'm pretty new to C.This is what i've used:
fp=fopen("/cygdrive/d/foldername/coordinates.txt","w");

fp=fopen("\\programs\\textfile.txt","w")

If you're using Cygwin, it's probably best to say it upfront -- avoids confusion.

For clarification, can you tell us whether fopen returns NULL when you open the file in a subdirectory?

If you're using Cygwin, it's probably best to say it upfront -- avoids confusion.

For clarification, can you tell us whether fopen returns NULL when you open the file in a subdirectory?

No, it doesn't return null.
There is just a blank output screen and the process keeps running.

So fopen just hangs, without returning? Interesting.

The usual suspects for not being able to open a file (e.g., wrong case, bad permissions) may not apply in your situation -- but I'm not entirely certain what your situation is, and I don't think I can be any more help at this point. Perhaps somebody familiar with cygwin will come along to supply advice.

Finally figured it out.
The problem was that the file I was trying to open did not have the values in the right order.It was supposed to have only two floats, instead it had a string at the beginning. How silly of me.
Here's the code:

#
fp1=fopen("/cygdrive/d/NACA2412/profile.txt","r");
#
while (feof(fp1)==0)
#
{
#
fscanf(fp1,"%f %f",&inlet_a[1],&outlet_a[1]);
#
}
#
fclose(fp1);

Anyways, thank you all for your help. Really learn't a lot.

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.