c-first-steps

a C playground
Index Commits Files Refs README
commit 1c57c42c1f3747c7e3125b61cf6d70182127a8e4
parent b36603c9bb1902f250984cf68bf8905d7b51c3cf
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Fri, 27 Nov 2020 22:29:55 -0300

Added ex26.c (not finished yet)

Diffstat:
A95.11/guia03/ex26.c | 42++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+), 0 deletions(-)
diff --git a/95.11/guia03/ex26.c b/95.11/guia03/ex26.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_LEN 100
+
+int main ( void ) {
+
+    char buffer[MAX_LEN], str1[MAX_LEN], str2[MAX_LEN], dest[MAX_LEN];
+    int i, j, num;
+
+    if(fgets(str1, MAX_LEN, stdin) == NULL)
+        return 1;
+
+    if(fgets(str2, MAX_LEN, stdin) == NULL)
+        return 1;
+
+    if(fgets(buffer, MAX_LEN, stdin) == NULL)
+       return 1;
+
+    num = atoi(buffer);
+
+//  This part couts the lengh of the first string;
+    for(i = 0; str1[i] != '\0'; i++)
+        ;
+    
+//  This part checks if the input number is bigger than
+//  the length of the string;
+    if(num > i)
+        return 1;
+
+    for(i = num, j = 0; str2[i] != '\0'; j++)
+        if(j <= num)
+            dest[j] = str1[j];
+
+        else 
+            dest[i] = str2[i];
+            i++;
+
+    printf("%s\n", dest);
+    return 0;
+}
+\ No newline at end of file