简体   繁体   中英

How to get the file path of a file in c(how to do this in windows)

I need to get the file path of a file i recently created in c

FILE *pFile;
pFile=fopen("client.txt","w");//create and open file in write mode

now how can i get the file path of client.txt?

You need the current working directory. getcwd will do this for you.

This should work

 #include <unistd.h>
 #include <linux/limits.h>

 char path[MAX_PATH + 1];
 char *cwd = getcwd(path, MAX_PATH);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM