zoukankan      html  css  js  c++  java
  • [C]使用argv的5种方法

    一:

    #include <stdio.h>
    int main(int argc, const char *argv[]) {
        int i;
        for (i = 0; i < argc; ++i) {
            printf("argv[%d] = %s
    ", i, argv[i]);
        }
        return 0;
    }

    二:

    #include <stdio.h>
    int main(int argc, const char *argv[]) {
        int i;
        for (i = 0; i < argc; ++i) {
            printf("argv[%d] = %s
    ", i, *(argv + i));
        }
        return 0;
    }

    三:

    #include <stdio.h>
    int main(int argc, const char *argv[]) {
        int i;
        for (i = 0; i < argc; ++i, argv++) {
            printf("argv[%d] = %s
    ", i, *(argv));
        }
        return 0;
    }

    四:

    #include <stdio.h>
    int main(int argc, const char *argv[]) {
        int i;
        for (i = 0; i < argc; ++i) {
            printf("argv[%d] = %s
    ", i, *(argv));
            argv++;
        }
        return 0;
    }

    五:

    #include <stdio.h>
    int main(int argc, const char *argv[]) {
        const char **p = argv; //用p来代替argv,这里的const不能丢掉
        int i;
        for (i = 0; i < argc; ++i) {
            printf("argv[%d] = %s
    ", i, *(p + i));
        }
        return 0;
    }
  • 相关阅读:
    线程同步技术
    线程调用
    进程与线程
    网络配置
    vi
    文件系统
    系统管理命令
    Linux常用命令
    Shell编程
    新版chrome touch警告处理办法
  • 原文地址:https://www.cnblogs.com/profesor/p/13208530.html
Copyright © 2011-2022 走看看