c-first-steps

a C playground
Index Commits Files Refs README
commit ffc5a7dd58aab5c2180d5fe208edd42cd1327152
parent 01a6c4e17cad4f27dc40b7f3d0484be0e808a715
Author: Martin J. Klockner <martin.cachari@gmail.com>
Date:   Tue, 17 Nov 2020 01:02:04 -0300

Added guia03/ folder as well as ej1.c, ej2.c & ej4.c

Diffstat:
D.vimrc | 4----
Aguia03/ej1.c | 20++++++++++++++++++++
Aguia03/ej2.c | 19+++++++++++++++++++
Aguia03/ej4.c | 17+++++++++++++++++
Aguia03/guia03.pdf | 0
5 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/.vimrc b/.vimrc
@@ -1,4 +0,0 @@
-set tabstop=4
-set autoindent
-syntax on
-colorscheme delek
diff --git a/guia03/ej1.c b/guia03/ej1.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+#define MAX_LEN 100
+
+
+int main(void) {
+
+    char s[MAX_LEN];
+
+    printf("> ");
+    scanf("%s", s);
+    puts(s);
+
+    printf("> ");
+    // gets(s); removed from std C11 because it's very unsecure
+    fgets(s, MAX_LEN, stdin);
+    puts(s);
+
+    return 0;
+}
diff --git a/guia03/ej2.c b/guia03/ej2.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <string.h>
+
+#define MAX_LEN 100
+#define ERR_EMPTY_MSG "no chars have been readed"
+
+int main(void) {
+    
+    char s[MAX_LEN];
+    if(fgets(s, MAX_LEN, stdin) == NULL) {
+        fprintf(stderr, ERR_EMPTY_MSG"\n");
+        return 1;
+    } else if(strcmp(s, "") == 0) {
+        fprintf(stderr, ERR_EMPTY_MSG"\n");
+        return 1;
+    }
+    printf("%s", s);
+    return 0;
+}
diff --git a/guia03/ej4.c b/guia03/ej4.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+
+    char s[] = "Hello world!\n";
+    char aux;
+    int n;
+
+    for(n = strlen(s); n >= 0; n--) {
+        aux = s[n];
+        if(aux != '\n')
+            putchar(aux);
+    }
+    putchar('\n');
+    return 0;
+}
diff --git a/guia03/guia03.pdf b/guia03/guia03.pdf
Binary files differ.