According to the man page strerror(errnum)
returns a char *
, but I get the following warning:
gcc temp.c -o temp
temp.c: In function ‘mystrerror’:
temp.c:10:4: warning: return makes pointer from integer without a cast [enabled by default]
I get a segfault When I run it with ./temp 0
but not ./temp 256
.
Could someone explain why this happens and how to fix it (if possible)?
temp.c
#include <stdio.h>
#include <errno.h>
char *mystrerror(int errnum)
{
switch (errnum) {
case 256:
return "My test";
default:
return strerror(errnum);
}
}
int main(int argc, char **argv)
{
int err;
if (argc > 1) {
err = atoi(argv[1]);
printf("test error (%d) %s\n", err, mystrerror(err));
}
return 0;
}