This works (notice the str+1 in the last line):
Code:
But this doesn't:
Code:
Is it because using str++ causes str to be used throughout the function and only incremented in the end, after the strchr(str++,ch) line, causing the non incremented str to be sent to all functions and causing an infinite loop?
Code:
char *strchr( char*str, char ch)
{
if (*str == '\0')
return NULL;
if (*str == ch)
return str;
strchr (str+1, ch);
}
But this doesn't:
Code:
char *strchr( char*str, char ch)
{
if (*str == '\0')
return NULL;
if (*str == ch)
return str;
strchr (str++, ch);
}
Is it because using str++ causes str to be used throughout the function and only incremented in the end, after the strchr(str++,ch) line, causing the non incremented str to be sent to all functions and causing an infinite loop?