Results 1 to 4 of 4
hi everybody
am having a little problem with open a file with its full path.
if((inFile = fopen(Buffer_Queue[i].path,"r")) == '
Thread: Open a file by its full path in C
'){ printf("Input file coudnt be opened\n"); return 0; } The file ...- 03-28-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 23
Open a file by its full path in C
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
- 03-29-2008 #2
Can you print out the value of Buffer_Queue[i].path and check if that file actually exists? It's possible that the string is something you don't expect.
Also, as a side note, fopen() returns a pointer, not a character. On most systems, NULL, '\0', and 0 are all the same value, but best practices is to use NULL for pointers, '\0' for chars, and 0 for ints, so that you can tell at a glance what your function is doing. I would suggest changing your check for '\0' into one for NULL.DISTRO=Arch
Registered Linux User #388732
- 03-29-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 23
i ve printed Buffer_Queue[i] and it s the rigth path of the file that i need to open and read.
normally if i use link "input.txt" and this one is in the current folder there is no problem:
like this :inFile = fopen("input.txt","r")) == NULL)
But now i would like to replace that with a path of a file which migth be somewhere in other folders (directory) or in another folder within the current folder
like this
like this :inFile = fopen("/docs/input.txt","r")) == NULL)
- 03-29-2008 #4Just Joined!
- Join Date
- Mar 2008
- Posts
- 23
Thanks Cebhan
i solved the problem.
best regards


Reply With Quote