Rewrite the following function so that it does not use any square brackets (not even in the parameter declarations) but does use the integer variable k.
// This function searches through str for the character chr.
// If the chr is found, it returns a pointer into str where
// the character was first found, otherwise NULL (not found).
constchar* findTheChar(constchar str[], char chr)
{
for (int k = 0; str[k] != 0; k++)
if (str[k] == chr)
return &str[k];
return NULL;
}
Does this mean I need to change the parameter type from const char to a string?
Ok, thanks alot, so I think I got it by basically replacing str[k] with *(str + k).
However, Im having trouble with the next part which states:
Now rewrite the function shown in part b so that it uses neither square brackets nor any integer variables. Your new function must not use any local variables other than the parameters.