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.
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
add a comment |
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.
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
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 forstrlcpy
(the BSD libc library function), you do not need to subtract 1 from destination buffer size asstrlcpy
will ensure the resulting destination string gets null terminated. You should probably replace that with something likesize_t n = strlcpy(datei, argv[3], sizeof(datei));
.
– Ian Abbott
Nov 9 at 12:07
add a comment |
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.
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
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.
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
c cygwin
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 forstrlcpy
(the BSD libc library function), you do not need to subtract 1 from destination buffer size asstrlcpy
will ensure the resulting destination string gets null terminated. You should probably replace that with something likesize_t n = strlcpy(datei, argv[3], sizeof(datei));
.
– Ian Abbott
Nov 9 at 12:07
add a comment |
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 forstrlcpy
(the BSD libc library function), you do not need to subtract 1 from destination buffer size asstrlcpy
will ensure the resulting destination string gets null terminated. You should probably replace that with something likesize_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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Nov 9 at 12:06
answered Nov 9 at 11:54
Peter
61618
61618
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 forstrlcpy
(the BSD libc library function), you do not need to subtract 1 from destination buffer size asstrlcpy
will ensure the resulting destination string gets null terminated. You should probably replace that with something likesize_t n = strlcpy(datei, argv[3], sizeof(datei));
.– Ian Abbott
Nov 9 at 12:07