Computing.Net > Forums > Programming > Just Joined! Join Date: Mar 200

Just Joined! Join Date: Mar 200

Reply to Message Icon

Original Message
Name: NKunzis
Date: March 28, 2008 at 06:04:26 Pacific
Subject: Just Joined! Join Date: Mar 200
OS: Linux
CPU/Ram: Intel / 512
Model/Manufacturer: HP
Comment:

hi everybody
am having a little problem with open a file with its full path.

if((inFile = fopen(Buffer_Queue[i].path,"r")) == '\0'){
printf("Input file coudnt be opened\n");

return 0;
}

The file cannot be found.
Buffer_Queue[i].path ; it s an array with paths of files that i need to read.
please help me to find out how to access the file inside the path.

Thanks

I got the right to be wrong
Coz my mistakes makes me strong


Report Offensive Message For Removal


Response Number 1
Name: klint
Date: March 28, 2008 at 07:29:26 Pacific
Reply: (edit)

A couple of things for you to look up in your C manual:
What type does fopen return?
And what is the type of '\0'?

However, the above is not the cause of your problem. It is something to do with the argument you pass to fopen(). You should check it by adding a debug trace statement immediately above the fopen() call:

printf("DEBUG: trying to open '%s'\n", Buffer_Queue[i].path);


Report Offensive Follow Up For Removal

Response Number 2
Name: NKunzis
Date: March 28, 2008 at 09:25:55 Pacific
Reply: (edit)

i ve added that statement debuging and it s printing the right path of the file. As u said maybe the arguments may be wrong. Coz fopen will search for files within the folder of the program. But i would like to access a folder and read files inside.
is threre a command to open a folder?

Thanks

I got the right to be wrong
Coz my mistakes makes me strong


Report Offensive Follow Up For Removal

Response Number 3
Name: klint
Date: March 28, 2008 at 09:45:29 Pacific
Reply: (edit)

No, fopen will use the current default directory (folder) from wherever you were when you ran the application. Nothing to do with where the application resides. To open a file in a specific folder, use the "/full/path/name" instead of just the name. Or just cd to the required directory before you run the program. Use ls to ensure the file printed in the debug statement really exists. Use cat to make sure the file is readable.


Report Offensive Follow Up For Removal

Response Number 4
Name: Razor2.3
Date: March 29, 2008 at 10:22:27 Pacific
Reply: (edit)

NKunzis: But i would like to access a folder and read files inside.

You mean you want to enumerate the files in a directory? I think you use readdir() on Linux systems.


Report Offensive Follow Up For Removal

Response Number 5
Name: NKunzis
Date: March 29, 2008 at 11:09:46 Pacific
Reply: (edit)

Thanks Razor2
The problem is solved.

Best regards

I got the right to be wrong
Coz my mistakes makes me strong


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Just Joined!
 
Join Date: Mar 200

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge