C语言文件路径设置

Python019

C语言文件路径设置,第1张

C语言中指定文件路径的三种方法

方法一:当前工程下的文件

fopen("demo.txt","rt")

方法二:当前工程下的 test文件夹 中文件

fopen(".\\test\\demo.txt","rt")

方法三:绝对路径,D盘下project文件夹中的文件

fopen("d:\\project\\demo.txt","rt")

用new或者malloc

char *fnasb(char *fn)

{

char *path_name = (char *)malloc(300)

strcpy(path_name, "E:\\cj\\")

strcat(path_name, fn)

return path_name

}

注:别忘记要free,tnasb同理