zoukankan      html  css  js  c++  java
  • C语言 main

    C语言 main

    main函数是操作系统调用的,第一个参数标明argv数组的成员数量,argv数组的每个成员都是char *类型

    • argv是命令行参数的字符串数组
    • argc代表命令行参数的数量,程序名字本身算一个参数

    案例

    案例:运行程序 传入参数并打印
    命令:gcc -o 文件.exe 文件.c
    执行:文件.exe 参数1 参数2

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    
    // gcc -o hello hello.c (4个参数“gcc”,“-o”,“hello”,“hello.c”)
    // int argc:表示床底参数的个数
    // char* argv[]={“gcc”,“-o”,“hello”,“hello.c”} 表示参数内容
    int main(int argc,char* argv[])
    {
        // gcc
        // 判断传入参数是否正确
        if (argc < 3)
        {
            printf("缺少参数
    ");
            // 返回错误
            return -1;
        }
    
        // 循环打印参数
        int i;
        for (i = 0; i < argc; i++)
        {
            printf("%s
    ", argv[i]);
        }
        return 0;
    }
  • 相关阅读:
    链接Oracle数据库
    Spring boot Mybatis
    Spring Boot 部署
    javaEE应用组件
    maven项目搭建步骤
    Spring Boot中Redis的使用
    Struts2 Hello,Wold
    使用JSON
    Spring中Quartz的配置
    Guice示例
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/12378487.html
Copyright © 2011-2022 走看看