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











up vote
0
down vote

favorite












I'm trying to run a simple program from command prompt for educational prupose to demonstrate the parameter exchange between a c program and operating system. I got the following output.



Commoand Prompt Output



I implemented the following code. Please ignore some of the printf outputs. 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("nnMAIN-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










share|improve this question




















  • 1




    You have to compile it.
    – Giovanni Cerretani
    Nov 9 at 11:18






  • 1




    You have to compile your program before you can run it. Cheers ähm, prost.
    – Swordfish
    Nov 9 at 11:18










  • size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1); is incorrect because you have a variable and a function with the same name. Also for strlcpy (the BSD libc library function), you do not need to subtract 1 from destination buffer size as strlcpy will ensure the resulting destination string gets null terminated. You should probably replace that with something like size_t n = strlcpy(datei, argv[3], sizeof(datei));.
    – Ian Abbott
    Nov 9 at 12:07















up vote
0
down vote

favorite












I'm trying to run a simple program from command prompt for educational prupose to demonstrate the parameter exchange between a c program and operating system. I got the following output.



Commoand Prompt Output



I implemented the following code. Please ignore some of the printf outputs. 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("nnMAIN-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










share|improve this question




















  • 1




    You have to compile it.
    – Giovanni Cerretani
    Nov 9 at 11:18






  • 1




    You have to compile your program before you can run it. Cheers ähm, prost.
    – Swordfish
    Nov 9 at 11:18










  • size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1); is incorrect because you have a variable and a function with the same name. Also for strlcpy (the BSD libc library function), you do not need to subtract 1 from destination buffer size as strlcpy will ensure the resulting destination string gets null terminated. You should probably replace that with something like size_t n = strlcpy(datei, argv[3], sizeof(datei));.
    – Ian Abbott
    Nov 9 at 12:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to run a simple program from command prompt for educational prupose to demonstrate the parameter exchange between a c program and operating system. I got the following output.



Commoand Prompt Output



I implemented the following code. Please ignore some of the printf outputs. 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("nnMAIN-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










share|improve this question















I'm trying to run a simple program from command prompt for educational prupose to demonstrate the parameter exchange between a c program and operating system. I got the following output.



Commoand Prompt Output



I implemented the following code. Please ignore some of the printf outputs. 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("nnMAIN-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







c cygwin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 11:18









Swordfish

8,29711234




8,29711234










asked Nov 9 at 11:13









xp10r3r

141




141








  • 1




    You have to compile it.
    – Giovanni Cerretani
    Nov 9 at 11:18






  • 1




    You have to compile your program before you can run it. Cheers ähm, prost.
    – Swordfish
    Nov 9 at 11:18










  • size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1); is incorrect because you have a variable and a function with the same name. Also for strlcpy (the BSD libc library function), you do not need to subtract 1 from destination buffer size as strlcpy will ensure the resulting destination string gets null terminated. You should probably replace that with something like size_t n = strlcpy(datei, argv[3], sizeof(datei));.
    – Ian Abbott
    Nov 9 at 12:07














  • 1




    You have to compile it.
    – Giovanni Cerretani
    Nov 9 at 11:18






  • 1




    You have to compile your program before you can run it. Cheers ähm, prost.
    – Swordfish
    Nov 9 at 11:18










  • size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1); is incorrect because you have a variable and a function with the same name. Also for strlcpy (the BSD libc library function), you do not need to subtract 1 from destination buffer size as strlcpy will ensure the resulting destination string gets null terminated. You should probably replace that with something like size_t n = strlcpy(datei, argv[3], sizeof(datei));.
    – Ian Abbott
    Nov 9 at 12:07








1




1




You have to compile it.
– Giovanni Cerretani
Nov 9 at 11:18




You have to compile it.
– Giovanni Cerretani
Nov 9 at 11:18




1




1




You have to compile your program before you can run it. Cheers ähm, prost.
– Swordfish
Nov 9 at 11:18




You have to compile your program before you can run it. Cheers ähm, prost.
– Swordfish
Nov 9 at 11:18












size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1); is incorrect because you have a variable and a function with the same name. Also for strlcpy (the BSD libc library function), you do not need to subtract 1 from destination buffer size as strlcpy will ensure the resulting destination string gets null terminated. You should probably replace that with something like size_t n = strlcpy(datei, argv[3], sizeof(datei));.
– Ian Abbott
Nov 9 at 12:07




size_t strlcpy = strlcpy(datei, argv[3], (int)sizeof(datei) - 1); is incorrect because you have a variable and a function with the same name. Also for strlcpy (the BSD libc library function), you do not need to subtract 1 from destination buffer size as strlcpy will ensure the resulting destination string gets null terminated. You should probably replace that with something like size_t n = strlcpy(datei, argv[3], sizeof(datei));.
– Ian Abbott
Nov 9 at 12:07












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Install gcc and some other compiler tools into your cygwin:



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. Compile your source:



$ gcc main.c -o main


Run your binary with the arguments:



$ ./main 1 2 date





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224651%2frunning-a-c-program-from-command-prompt-with-windows-10-and-cygwin%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Install gcc and some other compiler tools into your cygwin:



    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. Compile your source:



    $ gcc main.c -o main


    Run your binary with the arguments:



    $ ./main 1 2 date





    share|improve this answer



























      up vote
      0
      down vote













      Install gcc and some other compiler tools into your cygwin:



      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. Compile your source:



      $ gcc main.c -o main


      Run your binary with the arguments:



      $ ./main 1 2 date





      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        Install gcc and some other compiler tools into your cygwin:



        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. Compile your source:



        $ gcc main.c -o main


        Run your binary with the arguments:



        $ ./main 1 2 date





        share|improve this answer














        Install gcc and some other compiler tools into your cygwin:



        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. Compile your source:



        $ gcc main.c -o main


        Run your binary with the arguments:



        $ ./main 1 2 date






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 12:06

























        answered Nov 9 at 11:54









        Peter

        61618




        61618






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224651%2frunning-a-c-program-from-command-prompt-with-windows-10-and-cygwin%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff