I am trying to convert argv[1] to a floating point value but I end up with an compilation error. Here is my code.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
double circleArea = 3.14159 * atof(argv[1]) * atof(argv[1]); //this works
double circleArea = 3.14159 * (double) argv[1] * (double) argv[1]; //this does not
return 0;
}`
Why does the first statement compile and the second one does not? Should not the (double) argv[1]
be just as valid as atof(argv[1])
? I want to be able to do this in plain C not C++.
Update: These are the errors I get:
circleArea.c: In function ‘main’:
circleArea.c:9:2: error: pointer value used where a floating point value was expected
double area = 3.14159 * (double) argv[1] * (double) argv[1]; //this does not
^~~~~~
circleArea.c:9:2: error: pointer value used where a floating point value was expected