如何将 char** 中的每个字符串打印到 printf()?

How do I print out every string in a char** to printf()?

我有一个 main() 例程,它将所有命令行参数作为 'char **'。如何使用 printf() 在控制台中显示每个参数?

谢谢!

这很容易。请使用 google 或使用这个:

    #include <stdio.h>

    int main(int argc, char *argv[])
    {
        int i=argc;
        while((i--)>1)
            printf("%s\n",argv[i]);
        return 0;
    }

如果你指的是命令行参数,那么我认为最简单的方法是这样的

#include <stdio.h>

int main( int argc, char * argv[] )
{
    while ( *argv ) printf( "%s\n", *argv++ );
}

考虑到(C 标准,5.1.2.2.1 程序启动,p.N2)

— If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment. If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters.