4 int stringLength(const char* str
) {
7 for (; str
[result
]; ++result
);
12 void swap(char* v1
, char* v2
) {
18 void reverseString(char* str
) {
20 char* end
= str
+ stringLength(str
) - 1;
27 /** Perform a classical ROT13 permutation in-place */
28 void rot13(char* str
) {
30 char* end
= str
+ stringLength(str
);
32 while (cursor
< end
) {
33 if (*cursor
>= 'a' && *cursor
<= 'z') {
34 *cursor
= (*cursor
- 'a' + 13) % 26 + 'a';
35 } else if (*cursor
>= 'A' && *cursor
<= 'Z') {
36 *cursor
= (*cursor
- 'A' + 13) % 26 + 'A';
45 puts("Enter your message:");
46 int readValue
= scanf("%ms", &msg
);
53 printf("Initial value: \"%s\"\n", msg
);
55 printf("Reversed : \"%s\"\n", msg
);
56 reverseString(msg
); // Restore the original message
58 printf("ROT13 : \"%s\"\n", msg
);
59 free(msg
); // scanf("%ms") allocate dynamic memory