question 1)
the header file <stdio.h> is included in order to have
reference to the input/output function from C library. The <stdio.h> contains only function
references and not the definition of the functions. The <stdio.h> contains references to functions
like:
·
printf (out) output to stdout (default: screen)
·
scanf (in) reading from stdin (default: keyboard)
question 2)
char
*argv[] is an array of
pointer. Each pointer element is pointing to a string. Each string is an
argument from the command line.
Example: If your program name after compilation is
"myprogram" and you calling your program as following:
$myprogram -t test1 test2
So the argv is an array containing 4
pointers to the following string
argv[0] is a pointer to the string
"myprogram"
argv[1] is a pointer to the string
"-t"
argv[2] is a pointer to the string
"test1"
argv[3] is a pointer to the string
"test2"
question 3)
%d means integer and not double.
For double you can use %lf or %g
question 4)
%s means that you are printing
string
example related to argv:
printf("argv[0] =
%s\n", argv[0]);
printf("argv[1] =
%s\n", argv[1]);
printf("argv[2] =
%s\n", argv[2]);
printf("argv[3] =
%s\n", argv[3]);
based on question 2 the above prints give the following output:
argv[0] =
myprogram
argv[1] =
-t
argv[2] =
test1
argv[3] =
test2
|
0 komentar:
Posting Komentar