Reverse string

Explanation

C version

1
#include <stdio.h>
2
3
void reverse (char* string){
4
5
char *end = string;
6
while(*end != '\0'){
7
end++;
8
}
9
end--;
10
11
12
char* begin = string;
13
char tmp;
14
while(begin < end) {
15
tmp = *begin;
16
*begin = *end;
17
*end = tmp;
18
19
begin++;
20
end--;
21
}
22
}
Copied!

Test

1
int main() {
2
3
char test[100] = "abcdefg";
4
printf("sting: %s\n", test);
5
reverse(test);
6
printf("reverse: %s\n", test);
7
return 0;
8
9
}
Copied!
Copy link