summaryrefslogtreecommitdiff
path: root/graphs/piscine/ascii_carousel
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/piscine/ascii_carousel')
-rw-r--r--graphs/piscine/ascii_carousel/rot_x.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/graphs/piscine/ascii_carousel/rot_x.c b/graphs/piscine/ascii_carousel/rot_x.c
new file mode 100644
index 0000000..667106d
--- /dev/null
+++ b/graphs/piscine/ascii_carousel/rot_x.c
@@ -0,0 +1,26 @@
+#include <stddef.h>
+
+void rot_x(char *s, int x)
+{
+ if (s == NULL)
+ {
+ return;
+ }
+
+ if (x < 0)
+ {
+ x = 26 + x;
+ }
+
+ for (size_t i = 0; s[i]; i++)
+ {
+ if (s[i] >= 'a' && s[i] <= 'z')
+ {
+ s[i] = ((s[i] - 'a') + x) % 26 + 'a';
+ }
+ else if (s[i] >= 'A' && s[i] <= 'Z')
+ {
+ s[i] = ((s[i] - 'A') + x) % 26 + 'A';
+ }
+ }
+}