From ab79618ba19b920b7d55b0bad4d9665a15193bb7 Mon Sep 17 00:00:00 2001 From: pankunull Date: Thu, 14 Aug 2025 20:55:44 +0200 Subject: added src code --- ctof | Bin 0 -> 15648 bytes ctof.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ dir | Bin 0 -> 15624 bytes dir.c | 17 +++++++++++++++++ main | Bin 0 -> 15552 bytes main.c | 25 +++++++++++++++++++++++++ main2 | Bin 0 -> 15416 bytes main2.c | 6 ++++++ shift | Bin 0 -> 15672 bytes shift.c | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 124 insertions(+) create mode 100755 ctof create mode 100644 ctof.c create mode 100755 dir create mode 100644 dir.c create mode 100755 main create mode 100644 main.c create mode 100755 main2 create mode 100644 main2.c create mode 100755 shift create mode 100644 shift.c diff --git a/ctof b/ctof new file mode 100755 index 0000000..7a47ff7 Binary files /dev/null and b/ctof differ diff --git a/ctof.c b/ctof.c new file mode 100644 index 0000000..e61cfcd --- /dev/null +++ b/ctof.c @@ -0,0 +1,44 @@ +#include +#include +#include // for errno +#include // for INT_MAX, INT_MIN + + +/* + F = C x 9/5 + 32 +*/ + +int +main(int argc, char *argv[]) +{ + + if (argc < 2) { + printf("Usage: %s number\n", argv[0]); + return 1; + } + + char *endptr; + + errno = 0; // reset errno + + long value = strtol(argv[1], &endptr, 10); // base 10 + + if (endptr == argv[1]) { + printf("Error: No digits were found\n"); + return 1; + } + if (*endptr != '\0') { + printf("Warning: Trailing characters after number: %s\n", endptr); + return 1; + } + if ((value == LONG_MAX || value == LONG_MIN) && errno == ERANGE) { + printf("Error: Number out of range\n"); + return 1; + } + + float fah = value * 9/5 + 32; + + printf("Fahrenheit: %0.f\n", fah); + + return 0; +} diff --git a/dir b/dir new file mode 100755 index 0000000..7757a29 Binary files /dev/null and b/dir differ diff --git a/dir.c b/dir.c new file mode 100644 index 0000000..05803fd --- /dev/null +++ b/dir.c @@ -0,0 +1,17 @@ +#include +#include + +int main() { + DIR *d; + struct dirent *dir; + d = opendir("."); + if (d) { + while ((dir = readdir(d)) != NULL) { + printf("%s\n", dir->d_name); + } + closedir(d); + } else { + perror("opendir"); + } + return 0; +} diff --git a/main b/main new file mode 100755 index 0000000..37336e8 Binary files /dev/null and b/main differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..30d5c61 --- /dev/null +++ b/main.c @@ -0,0 +1,25 @@ +#include + +// Function that tries to change a number without pointer +void noPointerChange(int num) { + num = 100; // Changes local copy only +} + +// Function that changes a number using pointer +void pointerChange(int *numPtr) { + *numPtr = 100; // Changes original value through pointer +} + +int main() { + int value = 50; + + printf("Before noPointerChange: %d\n", value); + noPointerChange(value); + printf("After noPointerChange: %d\n", value); // value unchanged + + printf("Before pointerChange: %d\n", value); + pointerChange(&value); + printf("After pointerChange: %d\n", value); // value changed + + return 0; +} diff --git a/main2 b/main2 new file mode 100755 index 0000000..c35260e Binary files /dev/null and b/main2 differ diff --git a/main2.c b/main2.c new file mode 100644 index 0000000..c63efdb --- /dev/null +++ b/main2.c @@ -0,0 +1,6 @@ +#include + +main() +{ + printf("Hello C\n"); +} diff --git a/shift b/shift new file mode 100755 index 0000000..6429b03 Binary files /dev/null and b/shift differ diff --git a/shift.c b/shift.c new file mode 100644 index 0000000..c65b815 --- /dev/null +++ b/shift.c @@ -0,0 +1,32 @@ +#include + +void print_binary(unsigned char value) { + for (int i = 7; i >= 0; i--) { + printf("%d", (value >> i) & 1); + } + printf("\n"); +} + +int main() { + unsigned char value = 0; // start with all bits off + int bit; + + printf("Starting value: "); + print_binary(value); + + while (1) { + printf("Enter bit to toggle (0-7), or -1 to quit: "); + if (scanf("%d", &bit) != 1) break; + if (bit == -1) break; + if (bit < 0 || bit > 7) { + printf("Invalid bit.\n"); + continue; + } + + value ^= (1 << bit); // toggle the chosen bit + printf("Current value: "); + print_binary(value); + } + + return 0; +} -- cgit v1.2.3