简体   繁体   English

在Windows 10和Cygwin中从命令提示符运行AC程序

[英]Running a c program from command prompt with Windows 10 and Cygwin

I'm trying to run a simple program from command prompt for educational prupose to demonstrate the parameter exchange between ac program and operating system. 我正在尝试从命令提示符运行一个简单的程序,以进行教学,以演示ac程序和操作系统之间的参数交换。 I got the following output. 我得到以下输出。

提示输出

I implemented the following code. 我实现了以下代码。 Please ignore some of the printf outputs. 请忽略一些printf输出。 They're written in German. 它们是用德语写的。 I know I run the program with less parameter. 我知道我用较少的参数运行程序。 The output should be a hint on program was run with less parameter instead. 输出应该是在程序运行时使用较少参数的提示。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
    if(argc < 4)
        printf("Das Programm wurde mit %d anstatt den notwendigen 4 Parametern "
               "gestartet.", argc);
    else {
        int modus      = atoi(argv[1]);

        double niveau  = atof(argv[2]);

        char datei[13];
        size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1);

        printf("\n\nMAIN-Parameter");
        printf("\n#Parameter:\t%d", argc);
        printf("\nProgrammname:\t%s", argv[0]);
        printf("\nModus:\t%d", modus);
        printf("\nNiveau:\t%f", niveau);
        printf("\nDatei:\t%s", datei);
    }

    return 0;
}

Appreciate your input. 感谢您的输入。

Cheers 干杯

Install gcc and some other compiler tools into your cygwin: 在您的cygwin中安装gcc和其他一些编译器工具:

C:\cygwin64>setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel

Open a cygwin terminal. 打开一个cygwin终端。 Compile your source: 编译您的源代码:

$ gcc main.c -o main

Run your binary with the arguments: 使用以下参数运行二进制文件:

$ ./main 1 2 date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM