【发布时间】:2012-01-15 14:18:26
【问题描述】:
我正在寻找一种使用方法
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]是一个以null结尾的字符串,所以不需要传递长度,fopen()会在运行时使用strlen()来确定字符串的长度。
标签: c arguments fopen argv function-call