I am trying to learn the fundamentals of C, but I cannot figure out why this code doesn\'t work. The while loop in reverse() causes a bus error. I found almost identical code
Because end
and str
point to the same memory location -> they're two different names of the same object. You can avoid using two variables:
char foo[20] = "abcdefghi", tmp;
int counter = 0, length = strlen(foo);
for(counter, counter < length / 2; counter++) {
tmp = foo[counter];
foo[counter] = foo[length - counter];
foo[length - counter] = tmp;
}