summaryrefslogtreecommitdiff
path: root/graphs/piscine/str_revert/str_revert.c
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/piscine/str_revert/str_revert.c')
-rw-r--r--graphs/piscine/str_revert/str_revert.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/graphs/piscine/str_revert/str_revert.c b/graphs/piscine/str_revert/str_revert.c
new file mode 100644
index 0000000..31f7f3d
--- /dev/null
+++ b/graphs/piscine/str_revert/str_revert.c
@@ -0,0 +1,25 @@
+#include "str_revert.h"
+
+#include <stddef.h>
+
+void str_revert(char str[])
+{
+ if (*str == '\0')
+ {
+ return;
+ }
+
+ size_t len = 0;
+ for (; str[len]; len++)
+ {
+ continue;
+ }
+ len--;
+
+ for (size_t i = 0; i <= len / 2; i++)
+ {
+ char tmp = str[i];
+ str[i] = str[len - i];
+ str[len - i] = tmp;
+ }
+}