I want to open a file that is inside a folder in the current working directory like so:
fopen("/folder/file.txt","r");
I'm unable to do so in this way, i get a "No such file or directory" error.
How can i do this properly?
Thank you in advance for any help.
You have to mention that is a current directory. Try this,
fopen("./folder/file.txt","r");
Or
fopen("folder/file.txt","r");
If you mentioning like this /folder/file.txt
it will search the directory from the root directory. So this is the reason for getting the error.
Try:
fopen("./folder/file.txt","r"); /* dot means the directory itself */
or
fopen("folder/file.txt","r"); /* without the first backslash */
It seems that if i remove the first backslash it works.
Like so:
fopen("folder/file.txt","r");
weird.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.