变量作为文件名

Shw*_*eta 2 c file

是否可以在函数fopen()中使用变量作为文件名?有人可以帮一些例子吗?

Jef*_*ado 5

你只需要一个C字符串传入fopen().只需声明字符串char *(我建议使用const char *)变量,设置它并传入函数.

const char *filename = "my/path/to/the/file";
FILE *file = fopen(filename, "r");
Run Code Online (Sandbox Code Playgroud)