9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 2bfa2598184aed7ee361af6b3842bae0bf82085f
parent d0bf697f7ce58fc8c48b288075f6b37e4aa7ea8c
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Tue,  6 Apr 2021 23:30:19 -0300

Update: added ex20.c;

Diffstat:
Aguia05/ex20.c | 39+++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/guia05/ex20.c b/guia05/ex20.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <string.h>
+
+typedef enum {
+    OK,
+    ERROR_NULL_POINTER
+} status_t;
+
+status_t string_reverse(char *str);
+status_t swap_char(char *a, char *b);
+
+int main (void)
+{
+    char str[] = "Hello world!";
+
+    puts(str);
+    string_reverse(str);
+    puts(str);
+
+    return 0;
+}
+
+status_t string_reverse(char *str)
+{
+    if(str == NULL) return ERROR_NULL_POINTER;
+
+    size_t len = strlen(str);
+    for(size_t i = 0; i < (len / 2); i++)
+        swap_char(&str[i], &str[len - 1 - i]);
+
+    return OK;
+}
+
+void swap_char(char *a, char *b)
+{
+    *a = *a + *b;
+    *b = *a - *b;
+    *a = *a - *b;
+}