Luc*_*cas 1 c argv command-line-arguments
我正在学习如何在C中获取参数,但是,当我使用以下输入运行下面的代码时,第一个变为null.
输入: ./a.out a b c d e f g h i j k
输出: (null) b c d e f g h i j k
#include <stdio.h>
    int main(int argc, char *argv[])
    {
        int i = 2, j = 0;
        char *foo = argv[1];
        char *bar[10];
        while(j < 10 && i < argc)
        {
            bar[j++] = argv[i++];
        }
        bar[j] = NULL;
        printf("%s ", foo);
        for(j = 0; bar[j] != NULL; j++)
        {
            printf("%s ", bar[j]);
        }
        printf("\n");
        return 0;
    }
| 归档时间: | 
 | 
| 查看次数: | 170 次 | 
| 最近记录: |