PDA

View Full Version : C & getenv



cl333r
January 16th, 2009, 04:20 AM
Hi,
does anyone know why I get the warning "main.c:29: warning: initialization makes pointer from integer without a cast" for line


char *home = getenv("HOME");

and writing "char *home = (char *)getenv("HOME");" cancels the warning. The API states that a (char *) is being returned from getenv, why do I have to explicitly cast it?

dwhitney67
January 16th, 2009, 04:30 AM
Maybe because you forgot to include <stdlib.h>?

P.S. You should also consider declaring your variable as a const char*.


const char* home = getenv("HOME");

cl333r
January 16th, 2009, 05:08 AM
Thanks, that solved the issue.
The ability to reward the user seems to have been abolished.