This is function for reversing a string in C using recursive calls:
#include <stdio.h>
#include <string.h>
void revert(char* left, char* right) { // Should I pass char* like I'm doing now or are char** a better idea?
if(left == right) return;
char *ll = left; char* rr = right;
char tmp = right[0];
right[0] = left[0];
left[0] = tmp;
revert(++ll,--rr);
}
int main() {
char rev_string[] = "Some teststring";
printf("%s\n", rev_string);
revert(&rev_string[0],&rev_string[strlen(rev_string)-1]);//rev_string[strlen(rev_string)-1]);
printf("%s\n", rev_string);
return 0;
}
Can it be simplified? Can anything be written better?