]> zdv2.bktei.com Git - BK-2023-05.git/commitdiff
feat(src/kr_exercises/): Add dir for practice code
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Thu, 11 Aug 2022 23:59:30 +0000 (23:59 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Thu, 11 Aug 2022 23:59:30 +0000 (23:59 +0000)
src/20220811T01336Z_test..enumerations.c [new file with mode: 0644]
src/20220811T0229Z_test..temperature_conv.c [new file with mode: 0644]
src/kr_exercises/ch1/s1.2/c_to_f_float [new file with mode: 0755]
src/kr_exercises/ch1/s1.2/c_to_f_float.c [new file with mode: 0644]
src/kr_exercises/ch1/s1.2/compile.sh [new file with mode: 0755]
src/kr_exercises/ch1/s1.2/compile.sh~ [new file with mode: 0755]
src/kr_exercises/ch1/s1.2/f_to_c_float [new file with mode: 0755]
src/kr_exercises/ch1/s1.2/f_to_c_float.c [new file with mode: 0644]

diff --git a/src/20220811T01336Z_test..enumerations.c b/src/20220811T01336Z_test..enumerations.c
new file mode 100644 (file)
index 0000000..aa0d541
--- /dev/null
@@ -0,0 +1,27 @@
+/* Desc: Enumeration teste
+ * Usage: ./test
+ * Ref/Attrib: [5] https://www.geeksforgeeks.org/enumeration-enum-c/
+ */
+
+#include <stdio.h>
+//#include <stdlib.h>
+
+enum year{Jan, Feb, Mar, Apr, May, Jun, Jul,
+    Aug, Sep, Oct, Nov, Dec};
+
+int main(){
+  int i;
+  for (i=Jan; i<=Dec; i++)
+    printf("%d ", i);
+
+  printf("\n\nDone\n\n");
+  return 0;
+};
+
+
+
+
+/*
+ * Author: Steven Baltakatei Sandoval
+ * License: GPLv3+
+ */
diff --git a/src/20220811T0229Z_test..temperature_conv.c b/src/20220811T0229Z_test..temperature_conv.c
new file mode 100644 (file)
index 0000000..9577164
--- /dev/null
@@ -0,0 +1,37 @@
+/* Desc: simple temperature converter
+ * Usage: ./test
+ * Ref/Attrib: The C Programming Language, 2nd Edition, Section 1.2
+ */
+
+#include <stdio.h>
+//#include <stdlib.h>
+
+/* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */
+
+int main(){
+  int fahr, celsius;
+  int lower, upper, step;
+
+  lower = 0; /* lower limit of temperature table */
+  upper = 300; /* upper limit */
+  step = 20; /* step size */
+
+  fahr = lower;
+  while (fahr <= upper){
+    celsius = 5 * (fahr-32) / 9;
+    printf("%3d %6d\n", fahr, celsius);
+    fahr = fahr + step;
+  };
+
+  
+  printf("\n\nDone\n\n");
+  return 0;
+};
+
+
+
+
+/*
+ * Author: Steven Baltakatei Sandoval
+ * License: GPLv3+
+ */
diff --git a/src/kr_exercises/ch1/s1.2/c_to_f_float b/src/kr_exercises/ch1/s1.2/c_to_f_float
new file mode 100755 (executable)
index 0000000..965fc43
Binary files /dev/null and b/src/kr_exercises/ch1/s1.2/c_to_f_float differ
diff --git a/src/kr_exercises/ch1/s1.2/c_to_f_float.c b/src/kr_exercises/ch1/s1.2/c_to_f_float.c
new file mode 100644 (file)
index 0000000..609a3fd
--- /dev/null
@@ -0,0 +1,38 @@
+/* Desc: simple temperature converter
+ * Usage: ./s1..c_to_f_float.c
+ * Ref/Attrib: The C Programming Language, 2nd Edition, Section 1.2
+ */
+
+#include <stdio.h>
+//#include <stdlib.h>
+
+/* print Celsius-Fahrenheit table for celsius = -50, -40, ..., 100 */
+
+int main(){
+  float fahr, celsius;
+  int lower, upper, step;
+
+  lower = -50;   /* lower limit of temperature table */
+  upper = 100;   /* upper limit */
+  step  =   5;   /* step size */
+
+  celsius = lower;
+  printf(" °C,    °F\n");
+  while (celsius <= upper){
+    fahr = (celsius * (9.0 / 5.0))  + 32.0;
+    printf("%3.0f,%7.2f\n", celsius, fahr);
+    celsius = celsius + step;
+  };
+
+  
+  printf("\n\nDone\n\n");
+  return 0;
+};
+
+
+
+
+/*
+ * Author: Steven Baltakatei Sandoval
+ * License: GPLv3+
+ */
diff --git a/src/kr_exercises/ch1/s1.2/compile.sh b/src/kr_exercises/ch1/s1.2/compile.sh
new file mode 100755 (executable)
index 0000000..0b2a1ca
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+# Desc: Compiles all `.c` files in specified directory
+# Usage:  compile.sh [DIR]
+
+# Check args
+if [[ ! -d $1 ]]; then echo "FATAL:Not a dir:$1" 1>&2; exit 1; fi;
+
+for file in ./*.c; do
+    if [[ ! -f $file ]]; then echo "FATAL:Not a file:$file" 1>&2; exit 1; fi;
+    echo "STATUS:    file:$file" 1>&2;
+    file_out="${file%.c}";
+    echo "STATUS:file_out:$file_out" 1>&2;
+    gcc -o "$file_out" "$file" || echo "ERROR:Compile failed." 1>&2;
+    echo "" 1>&2;
+done;
diff --git a/src/kr_exercises/ch1/s1.2/compile.sh~ b/src/kr_exercises/ch1/s1.2/compile.sh~
new file mode 100755 (executable)
index 0000000..406a1c1
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+# Desc: Compiles all `.c` files in specified directory
+# Usage:  compile.sh [DIR]
+
+# Check args
+if [[ ! -d $1 ]]; then echo "FATAL:Not a dir:$1" 1>&2; exit 1; fi;
+
+for file in ./*.c; do
+    if [[ ! -f $file ]]; then echo "FATAL:Not a file:$file" 1>&2; exit 1; fi;
+    echo "STATUS:    file:$file" 1>&2;
+    file_out="${file%.c}";
+    echo "STATUS:file_out:$file_out" 1>&2;
+    gcc -o "$file_out" "$file"; # compile
+done;
diff --git a/src/kr_exercises/ch1/s1.2/f_to_c_float b/src/kr_exercises/ch1/s1.2/f_to_c_float
new file mode 100755 (executable)
index 0000000..2bb17cf
Binary files /dev/null and b/src/kr_exercises/ch1/s1.2/f_to_c_float differ
diff --git a/src/kr_exercises/ch1/s1.2/f_to_c_float.c b/src/kr_exercises/ch1/s1.2/f_to_c_float.c
new file mode 100644 (file)
index 0000000..6c5398a
--- /dev/null
@@ -0,0 +1,38 @@
+/* Desc: simple temperature converter
+ * Usage: ./s1..f_to_c_float.c
+ * Ref/Attrib: The C Programming Language, 2nd Edition, Section 1.2
+ */
+
+#include <stdio.h>
+//#include <stdlib.h>
+
+/* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */
+
+int main(){
+  float fahr, celsius;
+  int lower, upper, step;
+
+  lower =   0;   /* lower limit of temperature table */
+  upper = 300;   /* upper limit */
+  step  =  20;   /* step size */
+
+  fahr = lower;
+  printf(" °F,    °C\n");
+  while (fahr <= upper){
+    celsius = (5.0/9.0) * (fahr-32.0);
+    printf("%3.0f,%6.1f\n", fahr, celsius);
+    fahr = fahr + step;
+  };
+
+  
+  printf("\n\nDone\n\n");
+  return 0;
+};
+
+
+
+
+/*
+ * Author: Steven Baltakatei Sandoval
+ * License: GPLv3+
+ */