There are many problems with your code, some already mentioned by others such as argv
that needs to have a type of char *[]
.
First of all, if argc
is 1, then your malloc
will fail because allocating memory of size 0 doesn't make sense.
Second, printf("%lf\n", argc);
is incorrect. argc
is int
and you need to use %d
to print it. The reason you see 0, which is wrong, is this.
Third, x[tmp] = argv[tmp+1];
is incorrect too. argv[tmp+1]
is a char *
, which means it's a string. While x[tmp]
is a double
. You can't just assign a string to a double. What you need to do is to convert the string to a double, for example:
sscanf(argv[tmp+1], "%lf", &x[tmp]);
or
x[tmp] = strtod(argv[tmp+1]);
Hint: always compile your code with common warnings. With gcc, that would be -Wall
command line argument. The compiler can tell you about many of these mistakes.