问答详情
源自:6-2 [Linux C语言] main函数中的参数

最后一个输出成乱码了

sue@sue-G480:~/workspace/les3$ ./m3.out -l -a fdasd dad
argv is 5
argc[-1074445397] is 5
argc[-1074445388] is 5
argc[-1074445385] is 5
argc[-1074445382] is 5
argc[-1074445376] is 5
argc[0] is 5
成这个样子了这是什么情况啊

提问者:suuuue 2016-09-23 22:29

个回答

  • qq_way_0
    2016-09-24 11:20:54
    已采纳

    printf("argc[%d] is %s", i, argc[i]);

    后面两个参数应该是这样

  • qq_way_0
    2016-09-24 11:30:32

    #include <stdio.h>

    int main(int argc,char *argv[])

    {

        printf("hello world\n");

        for(int i = 0; i < argc; i++)

        {

            printf("argv[%d] is %s\n", i, argv[i]);

        }

        return 0;

    }