The input lakenum
is an integer from 1-5. Given that integer, the function should assign a name and return the string array to the main function, but instead I'm getting pointer errors:
error: return makes integer from pointer without a cast
error: function returns address of local variable
I call the function using printf ("%s", lakenamer(lakenum));
int lakenamer(lakenum) {
char lname[20] = "0";
if (lakenum == 1) {
strncpy(lname, "Ontario", 20);
} else if (lakenum == 2) {
strncpy(lname, "Erie", 20);
} else if (lakenum == 3) {
strncpy(lname, "Huron", 20);
} else if (lakenum == 4) {
strncpy(lname, "Muskoka", 20);
} else if (lakenum == 5) {
strncpy(lname, "Simcoe", 20);
}
printf("%s",lname);
return (lname);
}
strncpy
is a bad idea, you should usestrcpy
orsnprintf
instead. – Matt McNabb Feb 23 at 6:21