c-first-steps

a C playground
Index Commits Files Refs README
commit a1d2f5832509ab8f1fa99d5c9bd6e8a8ef77f92c
parent 37d54fd03844efe691c257182f0e5ee18b5a5701
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Sat,  8 May 2021 12:59:33 -0300

Update: Added old examples that wheren't commited;

Diffstat:
Athe-c-programming-language/chapter01/a.out | 0
Athe-c-programming-language/chapter01/ex05.c | 24++++++++++++++++++++++++
Athe-c-programming-language/chapter01/ex06.c | 15+++++++++++++++
Athe-c-programming-language/chapter01/ex07.c | 15+++++++++++++++
Mthe-c-programming-language/chapter01/ex09.c | 20++++++++++++--------
Athe-c-programming-language/chapter01/ex10.c | 16++++++++++++++++
6 files changed, 82 insertions(+), 8 deletions(-)
diff --git a/the-c-programming-language/chapter01/a.out b/the-c-programming-language/chapter01/a.out
Binary files differ.
diff --git a/the-c-programming-language/chapter01/ex05.c b/the-c-programming-language/chapter01/ex05.c
@@ -0,0 +1,24 @@
+/*    Exercise 1-5 - prints a table with degrees conversion    
+    from bigger to lower    */
+
+#include <stdio.h>
+
+/*    Celsius values;    */
+#define LOWER 0        /* Celsius start number */
+#define UPPER 50    /* Celsius max number */
+#define STEP 2        /* Step between Celsius numbers    */
+
+
+int main (void)
+{
+    float c, f;
+
+    printf("Celsius to Fahrenheit\n\n");
+
+    for(c = upper; c >= lower; c -= step) { 
+        f = (c * 9.0) / 5.0 + 32;
+        printf("%5.1f°C = %5.1f°F\n", c, f);
+    }
+
+    return 0;
+}
diff --git a/the-c-programming-language/chapter01/ex06.c b/the-c-programming-language/chapter01/ex06.c
@@ -0,0 +1,15 @@
+/*    Exercise 1-6 & 1-7    */
+
+#include <stdio.h>
+
+int main (void)
+{
+    int c;
+
+    printf("%d\n", EOF);
+
+    while ((c = getchar()) != EOF)
+        putchar(c);
+
+    return 0;
+}
diff --git a/the-c-programming-language/chapter01/ex07.c b/the-c-programming-language/chapter01/ex07.c
@@ -0,0 +1,15 @@
+/*    Exercise 1-6 & 1-7    */
+
+#include <stdio.h>
+
+int main (void)
+{
+    int c;
+
+    printf("%d\n", EOF);
+
+    while ((c = getchar()) != EOF)
+        putchar(c);
+
+    return 0;
+}
diff --git a/the-c-programming-language/chapter01/ex09.c b/the-c-programming-language/chapter01/ex09.c
@@ -3,18 +3,22 @@
 
 #include <stdio.h>
 
-int main( void ) {
-
-    
+int main( void ) 
+{
     unsigned long bl;
     bl = 0;
 
-    char aux;
-    while((aux = getchar()) != EOF) {
-        if (aux != ' ') {
+    int c;
+
+    while((c = getchar()) != EOF) {
+        if(c == ' ')
+            bl++;
+        else 
             bl = 0;
-        } else 
-            b++;
+
+        if(bl <= 1)
+            putchar(c);
     }
+
     return 0;
 }
diff --git a/the-c-programming-language/chapter01/ex10.c b/the-c-programming-language/chapter01/ex10.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int main (void)
+{
+    int c;
+
+    while((c = getchar()) != EOF) {
+        if(c == '\t')
+            printf("%s", "\\t");
+        else if(c == '\\')
+            printf("%s", "\\\\");
+        else
+            putchar(c);
+    }
+    return 0;
+}