Dear C-programming community,
I am trying to write a command-line parser that tests for successful conversion from string to double. I am getting the following warning from my gcc compiler for the code below: "warning: passing argument 2 of ‘strtod’ from incompatible pointer type." I am not sure how serious this warning is. I have been unsuccessful in getting rid of the warnings. Can anyone help me to improve my code and eliminate compiler warnings? I am not the greatest at pointers, so I could be missing something. I hope I followed proper protocol for posting code. Thanks.
Steve
Code:
/* -----------------------------------------------------------------------------------------------*/
#include <stdlib.h> /* for strtod */
#include <stdio.h>
#include <string.h> /* for strcpy */
void parseme( char **s ) {
double temp;
char **p;
int i, x, y;
for(i = 0; i < 2; i++) {
printf("\ns from parseme = %s\n", s[i]);
temp = strtod(s[i], &p);
printf("temp = %f\n", temp);
printf("address of s[0] = %p\n", s[i]);
printf("address of p = %p\n", p);
x = (int)p;
printf("x = %d\n", x);
y = (int)s[i];
printf("y = %d\n", y);
if(x == y) {
printf("conversion failed.\n\n");
}
else {
printf("conversion succeeded.\n\n");
}
}
}
/* -----------------------------------------------------------------------------------------------*/
/* -----------------------------------------------------------------------------------------------*/
void parseme( char ** );
int main( void ) {
char *s[2];
s[0] = "hello";
s[1] = "150";
parseme(s);
return 0;
}
/* -----------------------------------------------------------------------------------------------*/