samedi 21 février 2015

assign different strings to char array using a variable

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 im getting pointer errors (error: return makes integer from pointer without cast, 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);


}


thanks for the help in advance


Aucun commentaire:

Enregistrer un commentaire