我的代码如下c:
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int i;
for (i=0;i<argc;i++)
{
printf("Hello world! The arguments are %d, argc is %d and the string is %s\n",argc,i,argv);
}
return 0;
}
我无法在输出中正确查看参数。它有点加密。
我去了项目 - &gt;设置程序参数。虽然不行。请帮忙?
答案 0 :(得分:2)
您正在打印指针指针,正如编译器告诉您的那样:
test.c:12:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘char **’ [-Wformat=]
printf("Hello world! The arguments are %d, argc is %d and the string is %s\n",argc,i,argv);
^
argv
是一个指针数组,你想打印该数组的每个项目所指向的字符串:
更正后的代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int i;
for (i=0;i<argc;i++)
{
printf("Hello world! The arguments are %d, argc is %d and the string is %s\n",argc,i,argv[i]);
}
return 0;
}