I'm trying to call in a String, add a character based on certain conditions, update the longest String and then return the String.
I know that since I'm changing the String (by adding characters), I can't use const char* pointer, thus I must use a char array[].
But I also know that char array[] can't be returned, just the pointer. So I'm confused on how I can update a String (as a char array[]), and then return it (as a const char* pointer).
const char* longestWord(char line[])
{
int pos = 0;
char longest[250];
char ch = line[pos];
int longestLength = 0;
char current[250];
int currentLength = 0;
if(isalpha(ch) || isdigit(ch))
{
longest[longestLength] = ch;
longest[longestLength + 1] = '\0';
currentLength++;
}
pos++;
}
return longest;
return longestline?address of stack memory associated with local variable 'longest' returned