我正在尝试找到一种使用方法
FILE * fopen ( const char * filename, const char * mode );
但间接传递文件名。我还想知道如何间接调用名称直接取自 argv[] 的函数。我不想将字符串存储在缓冲区字符数组中。例如:
int main (int argc,char *argv[])
{
FILE *src;
...
src = fopen("argv[1]", "r"); //1st:how to insert the name of the argv[1] for example?
...
function_call(argc,argv); //2nd:and also how to call a function using directly argc argv
...
}
void create_files(char name_file1[],char name_file2[])
{...}
我是否必须存储长度和字符字符串才能调用函数? (关于第二个问题):)
最佳答案
你可以简单地使用argv[1]
,它是一个char *
:
if (argc < 2)
/* Error. */
src = fopen(argv[1], "r");
同样适用于 create_files
。
create_files(argv[1], argv[2]);
关于c - 如何使用已经在字符串数组中的名称进行 fopen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8870328/