2008814a45e411ba0929eb30fe508810618efd1c
4 // FIXME: Comment the code !!!
6 void swap(char* v1
, char* v2
) {
14 int stringLength(const char* str
) {
17 for(length
= 0; str
[length
] != '\0'; ++length
);
21 // FIXME: this function have issues with non english characters
22 void reverseString(char* str
) {
23 int length
= stringLength(str
);
25 for (int i
= length
- 1; i
>= length
/2; --i
) {
26 swap(&str
[i
], &str
[(length
- 1) - i
]);
30 // FIXME: this function have issues with non english characters
31 void permAlphaChar(char* str
, int key
) {
32 char alphabet
[26] = "abcdefghijklmnopqrstuvwxyz";
33 int str_length
= stringLength(str
);
35 for (int i
= 0; i
< str_length
; i
++) {
36 //if (str[i] == ' ') continue;
37 for (int j
= 0; j
< 26; j
++) {
38 if (str
[i
] == alphabet
[j
]) {
39 str
[i
] = alphabet
[(j
+key
) % 26];
41 } else if (str
[i
] == toupper(alphabet
[j
])) {
42 str
[i
] = toupper(alphabet
[(j
+key
) % 26]);
50 char rev_msg
[] = "Bonjour le monde";
51 int rev_length
= stringLength(rev_msg
);
52 char perm_msg
[] = "Bonjour a tous et toutes";
53 int perm_length
= stringLength(perm_msg
);
55 printf("La chaine de caracteres a inverser est \"%s\" et a pour longueur %d caractere(s)\n", rev_msg
, rev_length
);
56 reverseString(rev_msg
);
57 printf("La chaine inversee de caracteres est \"%s\"\n", rev_msg
);
61 printf("La chaine de caracteres a permuter est \"%s\" et a pour longueur %d caractere(s)\n", perm_msg
, perm_length
);
62 permAlphaChar(perm_msg
, 13);
63 printf("La chaine permutee de caracteres est \"%s\"\n", perm_msg
);