I want to make a reverse string function and I have done it like this:
void reverse_str(char s[]) {
int i, j;
char ch;
for(i = 0, j = strlen(s) - 1; i < j; i++, j--) {
ch = s[i];
s[i] = s[j];
s[j] = ch;
}
return ;
}
But for some reason when I change i < j
to i != j
I get a segmentation fault. This also happens when i
and j
are pointers. Why?