summaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/bungus.c5
-rw-r--r--c/calculator.c10
-rw-r--r--c/playlist.c38
-rw-r--r--c/pointers.c9
-rw-r--r--c/print.c11
-rw-r--r--c/structs.c49
-rw-r--r--c/switch.c29
-rw-r--r--c/webserver.c29
8 files changed, 180 insertions, 0 deletions
diff --git a/c/bungus.c b/c/bungus.c
new file mode 100644
index 0000000..0a06373
--- /dev/null
+++ b/c/bungus.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+int main() {
+ printf("boner\n");
+} \ No newline at end of file
diff --git a/c/calculator.c b/c/calculator.c
new file mode 100644
index 0000000..06c115c
--- /dev/null
+++ b/c/calculator.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main() {
+ printf("input expression: ");
+ char input[16];
+ fgets(input,16,stdin);
+ printf("input: %s",input);
+ return 0;
+}
+
diff --git a/c/playlist.c b/c/playlist.c
new file mode 100644
index 0000000..42c7ced
--- /dev/null
+++ b/c/playlist.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <stdbool.h>
+
+int main() {
+ bool running = true;
+ while (running) {
+
+ // Print menu options
+ printf("Welcome to the text-based menu!\n");
+ printf("1. Option 1\n");
+ printf("2. Option 2\n");
+ printf("3. Option 3\n");
+ printf("4. Exit\n");
+
+ // Get user input
+ int option;
+ scanf("%d", &option);
+
+ // Handle user input
+ switch (option) {
+ case 1:
+ printf("You chose option 1!\n");
+ break;
+ case 2:
+ printf("You chose option 2!\n");
+ break;
+ case 3:
+ printf("You chose option 3!\n");
+ break;
+ case 4:
+ running = false;
+ printf("You chose to exit the menu.\n");
+ break;
+ default:
+ printf("Invalid input. Please try again.\n");
+ }
+ }
+}
diff --git a/c/pointers.c b/c/pointers.c
new file mode 100644
index 0000000..bdbba0b
--- /dev/null
+++ b/c/pointers.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main() {
+ int x = 8;
+ int *point = &x;
+ int **pointpoint = &point;
+ printf("x: %d\n", **pointpoint);
+ return 0;
+}
diff --git a/c/print.c b/c/print.c
new file mode 100644
index 0000000..d1533d9
--- /dev/null
+++ b/c/print.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main() {
+ // char string[21] = "this is a char array";
+ for (float i = 0; i < 100; i += 0.0001) {
+ // printf(string);
+ printf("number incoming: %f\n",i);
+ // printf("\n");
+ }
+ return 0;
+}
diff --git a/c/structs.c b/c/structs.c
new file mode 100644
index 0000000..4e8670a
--- /dev/null
+++ b/c/structs.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <string.h>
+
+struct dog {
+ int age;
+ int weight;
+ char color[16];
+ char name[16];
+};
+
+
+void menu(struct dog atlas) {
+ int option;
+
+ do {
+ printf("dawg\n");
+ printf("1. Option 1\n");
+ printf("2. Option 2\n");
+ printf("3. Option 3\n");
+ printf("4. Exit\n");
+ scanf("%d", &option);
+
+ switch (option) {
+ case 1:
+ printf("name: %s\n", atlas.name);
+ break;
+ case 2:
+ printf("age: %d\n", atlas.age);
+ break;
+ case 4:
+ printf("exiting...\n");
+ break;
+ default:
+ printf("Invalid option\n");
+ }
+ } while (option != 4);
+}
+
+int main() {
+ struct dog atlas;
+ atlas.age = 7;
+ atlas.weight = 77;
+ strcpy(atlas.color, "black");
+ strcpy(atlas.name, "atlas");
+
+ menu(atlas);
+ return 0;
+}
+
diff --git a/c/switch.c b/c/switch.c
new file mode 100644
index 0000000..46d1cf9
--- /dev/null
+++ b/c/switch.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+enum options {
+ STOP = 'q',
+ CONTINUE = 'c',
+ NEW = 'n',
+};
+
+
+
+int main() {
+ char optbuff[4];
+
+ while (optbuff[0] != STOP) {
+ printf("choose sumth");
+ scanf("%4s", optbuff);
+
+ switch (optbuff[0]) {
+ case STOP:
+ printf("stop\n");
+ break;
+ case CONTINUE:
+ printf("continue\n");
+ break;
+ break;
+ }
+ return 0;
+}
+}
diff --git a/c/webserver.c b/c/webserver.c
new file mode 100644
index 0000000..5de519c
--- /dev/null
+++ b/c/webserver.c
@@ -0,0 +1,29 @@
+#include <sys/socket.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/sendfile.h>
+#include <unistd.h>
+#include <netinet/in.h>
+
+// followed that one guys tutorial. can only send 256 bytes per request
+void main() {
+ int sock = socket(AF_INET, SOCK_STREAM, 0);
+ struct sockaddr_in addr = {
+ AF_INET,
+ 0x901f,
+ 0
+ };
+ bind(sock, &addr, sizeof(addr));
+ listen(sock, 32);
+ int client_fd = accept(sock, 0, 0);
+ char buffer[256] = {0};
+ recv(client_fd, buffer, 256, 0);
+
+ char* file = buffer + 5;
+ *strchr(file, ' ') = 0;
+ int opened_fd = open(file, O_RDONLY);
+ sendfile(client_fd, opened_fd, 0, 256);
+ close(opened_fd);
+ close(client_fd);
+ close(sock);
+}