Ok - so i'm learning C - specifically for this question pointers and functions.
I have this function
char *RemoveVowels(char *str) {
char outStr[40];
for (size_t i = 0; i < sizeof(outStr); i++)
outStr[i] = '\0';
char *c = outStr;
while (*str) {
switch (*str)
{
case 'A':case'a':
case 'E':case'e':
case 'I':case'i':
case 'O':case'o':
case 'U':case'u':
*str++;
break;
default:
*c++ = *str++;
break;
}
}
*c = '\0';
return outStr;
}
I'm just trying to get my head around how pointers play with arrays and how they are used to return strings.
When i call this function with
puts(RemoveVowels("some string with vowels in it"));
The function works, i'm not concerned with better ways to do it, i'm sure there are, it's the pointer/array/string manipulation that i'm interested in.
I can see the string has created a new string and removed the vowels in outStr. However i just get gibberish from puts(), why doesn't the string get printed, i ensured it ended with the NULL?
Be gentle i'm learning :)