I was wondering what this code should print. I wanted to check whether it prints we can, can we
or we can
, but instead i got segmentation fault.
Here is the code:
char* mysubstr() {
char* x = "Yes we can, can we";
char* y = "we can";
char* tmp = x;
while(*tmp) {
if (*tmp == *y)
return *tmp;
tmp++;
}
return x;
}
void main() {
printf("%s", mysubstr());
}
I think the wrong part is the return *tmp;
, but why? What's wrong with that?