I'm trying to make a reverse string in place function. I got it to work, but I wanted to get fancy w/pointers and now get "Segmentation Fault (core dumped)".
I don't understand what I'm doing wrong. Help appreciated.
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13
void swap(char *a, char *b) {
char temp = *b;
*b = *a;
*a = temp;
}
void str_rev(char *s) {
int n = strlen(s) - 1;
for(int i = 0; i < (n+1)/2; i++)
swap(&s[i], &s[n-i]);
}