Commit | Line | Data |
---|---|---|
63647b82 JB |
1 | #include <stdio.h> |
2 | ||
3 | //FIXME: Comment the code !!! | |
4 | ||
5 | void swap(char* v1, char* v2) { | |
6 | if (v1 != v2) { | |
7 | char tmp = *v1; | |
8 | *v1 = *v2; | |
9 | *v2 = tmp; | |
10 | } | |
11 | } | |
12 | ||
13 | int stringLength(const char* str) { | |
14 | int length; | |
15 | ||
16 | for(length = 0; str[length] != '\0'; ++length); | |
17 | return length; | |
18 | } | |
19 | ||
20 | // FIXME: this function have issues with non english characters | |
21 | void reverseString(char* str) { | |
22 | int length = stringLength(str); | |
23 | ||
24 | for (int i = length - 1; i >= length/2; --i) { | |
25 | swap(&str[i], &str[(length - 1) - i]); | |
26 | } | |
27 | } | |
28 | ||
29 | int main() { | |
30 | char msg[] = "Bonjour et a bientot"; | |
31 | int length = stringLength(msg); | |
32 | ||
33 | printf("La chaine de caracteres est \"%s\" et a pour longueur %d caractere(s)\n", msg, length); | |
34 | reverseString(msg); | |
35 | printf("La chaine inversee de caracteres est \"%s\"\n", msg); | |
36 | ||
37 | return 0; | |
38 | } |