c-first-steps

a C playground
Index Commits Files Refs README
commit 15c9a8f3d30b2ad056f3edd926c69061c6207654
parent 17ffd82ffdf845875a714be020f1f56dc1473153
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Tue, 24 Nov 2020 10:53:03 -0300

Added ex17.c

Diffstat:
A95.11/guia03/ex17.c | 34++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+), 0 deletions(-)
diff --git a/95.11/guia03/ex17.c b/95.11/guia03/ex17.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+
+#define MAX_LEN 100
+
+
+int main ( void ) {
+
+    int i, j;
+    
+    char s1[MAX_LEN];
+    char s2[MAX_LEN];
+    
+    if(fgets(s1, MAX_LEN, stdin) == NULL)
+        return 1;
+
+    if(fgets(s2, MAX_LEN, stdin) == NULL)
+        return 1;
+
+    if(strlen(s2) > strlen(s1))
+        return 1;
+
+    for(i = 0; s1[i] != '\0'; i++)
+        if(s1[i] == s2[0])
+            for(j = 0; (s2[j] != '\0'); j++)
+                if(s1[i] == s2[j]) {
+                    putchar(s1[i]);
+                    i++;
+                }
+    putchar('\n');
+    return 0;
+}
+
+