diff options
author | pankunull <panku_null@proton.me> | 2025-08-14 20:55:44 +0200 |
---|---|---|
committer | pankunull <panku_null@proton.me> | 2025-08-14 20:55:44 +0200 |
commit | ab79618ba19b920b7d55b0bad4d9665a15193bb7 (patch) | |
tree | 76d0b352a5bc5df7a6ed4d64cf44635c7dc31caa | |
parent | 27552efa93073b5a64dfa1cc82d110e98edb269f (diff) |
added src code
-rwxr-xr-x | ctof | bin | 0 -> 15648 bytes | |||
-rw-r--r-- | ctof.c | 44 | ||||
-rwxr-xr-x | dir | bin | 0 -> 15624 bytes | |||
-rw-r--r-- | dir.c | 17 | ||||
-rwxr-xr-x | main | bin | 0 -> 15552 bytes | |||
-rw-r--r-- | main.c | 25 | ||||
-rwxr-xr-x | main2 | bin | 0 -> 15416 bytes | |||
-rw-r--r-- | main2.c | 6 | ||||
-rwxr-xr-x | shift | bin | 0 -> 15672 bytes | |||
-rw-r--r-- | shift.c | 32 |
10 files changed, 124 insertions, 0 deletions
Binary files differ @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> // for errno +#include <limits.h> // 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; +} Binary files differ@@ -0,0 +1,17 @@ +#include <stdio.h> +#include <dirent.h> + +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; +} Binary files differ@@ -0,0 +1,25 @@ +#include <stdio.h> + +// 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; +} Binary files differ@@ -0,0 +1,6 @@ +#include <stdio.h> + +main() +{ + printf("Hello C\n"); +} Binary files differ@@ -0,0 +1,32 @@ +#include <stdio.h> + +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; +} |