给定我在命令行中使用的命令行工具,如下所示:./tool img/file.png
如何将第一个参数分配给变量?我尝试了*argv[1]
, &argv[1]
,malloc(sizeof(argv[1]))
但随后出现invalid initializer
错误。我只是没有得到基本的 C 概念还是我卡在哪里了?谢谢你的帮助!
int main(int argc, char ** argv) {
char block1_arg_Filename[] = "img/file.png"; //that's how it works but I don't need it
char block1_arg_Filename[] = argv[1]; // don't get it to work but that's how I need it
[...]
return 0;
}