summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/c/_Makefile (renamed from src/c/__Makefile__)0
-rw-r--r--src/c/exercise1/Makefile30
-rwxr-xr-xsrc/c/exercise1/countbin0 -> 15592 bytes
-rw-r--r--src/c/exercise1/count.c33
-rw-r--r--src/c/hello-c/Makefile30
-rw-r--r--src/c/hello-c/Makefile_001.log1
-rwxr-xr-xsrc/c/hello-c/hellobin0 -> 15440 bytes
-rw-r--r--src/c/hello-c/hello.c3
-rw-r--r--src/c/sizeof/Makefile30
-rwxr-xr-xsrc/c/sizeof/mainbin0 -> 15488 bytes
-rw-r--r--src/c/sizeof/main.c50
11 files changed, 177 insertions, 0 deletions
diff --git a/src/c/__Makefile__ b/src/c/_Makefile
index d6e2bf1..d6e2bf1 100644
--- a/src/c/__Makefile__
+++ b/src/c/_Makefile
diff --git a/src/c/exercise1/Makefile b/src/c/exercise1/Makefile
new file mode 100644
index 0000000..9a5793b
--- /dev/null
+++ b/src/c/exercise1/Makefile
@@ -0,0 +1,30 @@
+# Minimal Makefile to compile count.c into an executable named main
+
+# Compiler
+CC = gcc
+
+
+# Flags
+CFLAGS = -Wall -Wextra -O2
+
+
+# Default target
+# Tells make what dependencies to compile
+all: count
+
+
+# Dependency 'count'
+# count.c is the source file
+count: count.c
+ $(CC) $(CFLAGS) -o count count.c
+
+
+# Test target
+test: count
+ @echo -n "count.c test............................"
+ @./count >/dev/null 2>&1 && echo "OK" || echo "FAILED"
+
+
+# Clean target
+clean:
+ rm -f count
diff --git a/src/c/exercise1/count b/src/c/exercise1/count
new file mode 100755
index 0000000..3e40c87
--- /dev/null
+++ b/src/c/exercise1/count
Binary files differ
diff --git a/src/c/exercise1/count.c b/src/c/exercise1/count.c
new file mode 100644
index 0000000..385fb71
--- /dev/null
+++ b/src/c/exercise1/count.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+
+int
+main()
+{
+
+ int c, i, nwhite, nother;
+ int ndigit[10];
+
+ nwhite = nother = 0;
+
+ for (i = 0; i < 10; ++i)
+ ndigit[i] = 0;
+
+ while ((c = getchar()) != EOF)
+ if (c >= '0' && c <= '9')
+ ++ndigit[c-'0'];
+ else if (c == ' ' || c == '\n' || c == '\t')
+ ++nwhite;
+ else
+ ++nother;
+
+ printf("digits =");
+
+ for (i = 0; i < 10; ++i)
+ printf(" %d", ndigit[i]);
+
+ printf(", white space = %d, other = %d\n",
+ nwhite, nother);
+
+ return 0;
+}
+
diff --git a/src/c/hello-c/Makefile b/src/c/hello-c/Makefile
new file mode 100644
index 0000000..876f118
--- /dev/null
+++ b/src/c/hello-c/Makefile
@@ -0,0 +1,30 @@
+# Minimal Makefile to compile hello.c into an executable named main
+
+# Compiler
+CC = gcc
+
+
+# Flags
+CFLAGS = -Wall -Wextra -O2
+
+
+# Default target
+# Tells make what dependencies to compile
+all: hello
+
+
+# Dependency 'hello'
+# hello.c is the source file
+hello: hello.c
+ $(CC) $(CFLAGS) -o hello hello.c
+
+
+# Test target
+test: hello
+ @echo -n "hello.c test............................"
+ @./hello >/dev/null 2>&1 && echo "OK" || echo "FAILED"
+
+
+# Clean target
+clean:
+ rm -f hello
diff --git a/src/c/hello-c/Makefile_001.log b/src/c/hello-c/Makefile_001.log
new file mode 100644
index 0000000..282d1b5
--- /dev/null
+++ b/src/c/hello-c/Makefile_001.log
@@ -0,0 +1 @@
+make: Nothing to be done for 'all'.
diff --git a/src/c/hello-c/hello b/src/c/hello-c/hello
new file mode 100755
index 0000000..1d127b0
--- /dev/null
+++ b/src/c/hello-c/hello
Binary files differ
diff --git a/src/c/hello-c/hello.c b/src/c/hello-c/hello.c
index c63efdb..4aff095 100644
--- a/src/c/hello-c/hello.c
+++ b/src/c/hello-c/hello.c
@@ -1,6 +1,9 @@
#include <stdio.h>
+int
main()
{
printf("Hello C\n");
+
+ return 0;
}
diff --git a/src/c/sizeof/Makefile b/src/c/sizeof/Makefile
new file mode 100644
index 0000000..d6e2bf1
--- /dev/null
+++ b/src/c/sizeof/Makefile
@@ -0,0 +1,30 @@
+# Minimal Makefile to compile main.c into an executable named main
+
+# Compiler
+CC = gcc
+
+
+# Flags
+CFLAGS = -Wall -Wextra -O2
+
+
+# Default target
+# Tells make what dependencies to compile
+all: main
+
+
+# Dependency 'main'
+# main.c is the source file
+main: main.c
+ $(CC) $(CFLAGS) -o main main.c
+
+
+# Test target
+test: main
+ @echo -n "main.c test............................"
+ @./main >/dev/null 2>&1 && echo "OK" || echo "FAILED"
+
+
+# Clean target
+clean:
+ rm -f main
diff --git a/src/c/sizeof/main b/src/c/sizeof/main
new file mode 100755
index 0000000..d902a63
--- /dev/null
+++ b/src/c/sizeof/main
Binary files differ
diff --git a/src/c/sizeof/main.c b/src/c/sizeof/main.c
new file mode 100644
index 0000000..0d16080
--- /dev/null
+++ b/src/c/sizeof/main.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdint.h> // for fixed-width integer types
+#include <stddef.h> // for size_t, ptrdiff_t
+#include <limits.h> // for limits of fundamental types
+#include <inttypes.h> // for PRId64 macros etc.
+
+int main(void) {
+ printf("=== Fundamental integer types ===\n");
+ printf("char : %zu byte(s) (%zu bit) range: %d to %d\n",
+ sizeof(char), sizeof(char) * 8, CHAR_MIN, CHAR_MAX);
+ printf("short : %zu byte(s) (%zu bit) range: %d to %d\n",
+ sizeof(short), sizeof(short) * 8, SHRT_MIN, SHRT_MAX);
+ printf("int : %zu byte(s) (%zu bit) range: %d to %d\n",
+ sizeof(int), sizeof(int) * 8, INT_MIN, INT_MAX);
+ printf("long : %zu byte(s) (%zu bit) range: %ld to %ld\n",
+ sizeof(long), sizeof(long) * 8, LONG_MIN, LONG_MAX);
+ printf("long long : %zu byte(s) (%zu bit) range: %lld to %lld\n",
+ sizeof(long long), sizeof(long long) * 8, LLONG_MIN, LLONG_MAX);
+
+ printf("\n=== Fixed-width integer types (from <stdint.h>) ===\n");
+ printf("int8_t : %zu byte(s) (%zu bit) range: %" PRId8 " to %" PRId8 "\n",
+ sizeof(int8_t), sizeof(int8_t) * 8, INT8_MIN, INT8_MAX);
+ printf("int16_t : %zu byte(s) (%zu bit) range: %" PRId16 " to %" PRId16 "\n",
+ sizeof(int16_t), sizeof(int16_t) * 8, INT16_MIN, INT16_MAX);
+ printf("int32_t : %zu byte(s) (%zu bit) range: %" PRId32 " to %" PRId32 "\n",
+ sizeof(int32_t), sizeof(int32_t) * 8, INT32_MIN, INT32_MAX);
+ printf("int64_t : %zu byte(s) (%zu bit) range: %" PRId64 " to %" PRId64 "\n",
+ sizeof(int64_t), sizeof(int64_t) * 8, INT64_MIN, INT64_MAX);
+
+ printf("\n=== Unsigned fixed-width types ===\n");
+ printf("uint8_t : %zu byte(s) (%zu bit) range: 0 to %" PRIu8 "\n",
+ sizeof(uint8_t), sizeof(uint8_t) * 8, UINT8_MAX);
+ printf("uint16_t : %zu byte(s) (%zu bit) range: 0 to %" PRIu16 "\n",
+ sizeof(uint16_t), sizeof(uint16_t) * 8, UINT16_MAX);
+ printf("uint32_t : %zu byte(s) (%zu bit) range: 0 to %" PRIu32 "\n",
+ sizeof(uint32_t), sizeof(uint32_t) * 8, UINT32_MAX);
+ printf("uint64_t : %zu byte(s) (%zu bit) range: 0 to %" PRIu64 "\n",
+ sizeof(uint64_t), sizeof(uint64_t) * 8, UINT64_MAX);
+
+ printf("\n=== Pointer and memory-related types ===\n");
+ printf("void* : %zu byte(s) (%zu bit)\n",
+ sizeof(void*), sizeof(void*) * 8);
+ printf("size_t : %zu byte(s) (%zu bit) range: 0 to %zu\n",
+ sizeof(size_t), sizeof(size_t) * 8, (size_t)-1);
+ printf("ptrdiff_t : %zu byte(s) (%zu bit)\n",
+ sizeof(ptrdiff_t), sizeof(ptrdiff_t) * 8);
+
+ return 0;
+}
+