From 7b21727285e50b0b050c4ddd70d07542229c5366 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:17:03 -0700 Subject: init --- c/baller.h | 1 + c/bungus.c | 5 +++++ c/calculator.c | 10 ++++++++++ c/factorial.c | 18 ++++++++++++++++++ c/float.c | 11 +++++++++++ c/head.c | 7 +++++++ c/key.c | 18 ++++++++++++++++++ c/ncurses.c | 18 ++++++++++++++++++ c/opengl.c | 26 ++++++++++++++++++++++++++ c/pointers.c | 9 +++++++++ c/print.c | 11 +++++++++++ c/sig.c | 13 +++++++++++++ c/structs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ c/sw.c | 27 +++++++++++++++++++++++++++ c/webserver.c | 29 +++++++++++++++++++++++++++++ 15 files changed, 252 insertions(+) create mode 100644 c/baller.h create mode 100644 c/bungus.c create mode 100644 c/calculator.c create mode 100644 c/factorial.c create mode 100644 c/float.c create mode 100644 c/head.c create mode 100644 c/key.c create mode 100644 c/ncurses.c create mode 100644 c/opengl.c create mode 100644 c/pointers.c create mode 100644 c/print.c create mode 100644 c/sig.c create mode 100644 c/structs.c create mode 100644 c/sw.c create mode 100644 c/webserver.c (limited to 'c') diff --git a/c/baller.h b/c/baller.h new file mode 100644 index 0000000..c014e67 --- /dev/null +++ b/c/baller.h @@ -0,0 +1 @@ +static char BALLER[] = "baller"; 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 + +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 + +int main() { + printf("input expression: "); + char input[16]; + fgets(input,16,stdin); + printf("input: %s",input); + return 0; +} + diff --git a/c/factorial.c b/c/factorial.c new file mode 100644 index 0000000..4ee0720 --- /dev/null +++ b/c/factorial.c @@ -0,0 +1,18 @@ +#include + +long fact(long n) { + if (n == 0) { + return 1; + } + else return(n*fact(n-1)); +} + +int main() { + printf("enter a POSITIVE integer... "); + long input; + scanf("%d", &input); + long output = fact(input); + printf("output: %lld\n", output); + + return 0; +} diff --git a/c/float.c b/c/float.c new file mode 100644 index 0000000..f02a177 --- /dev/null +++ b/c/float.c @@ -0,0 +1,11 @@ +#include +#include + +// this showcases floating point innaccuracy due to needing to represent them in binary + +void main() { + float ye = 6.28; + printf("%.4f\n", ye); + printf("%.8f\n", ye); + printf("%.12f\n", ye); +} diff --git a/c/head.c b/c/head.c new file mode 100644 index 0000000..c3ff4fd --- /dev/null +++ b/c/head.c @@ -0,0 +1,7 @@ +#include +#include "baller.h" + +int main() { +printf("%s\n", BALLER); +return 0; +} diff --git a/c/key.c b/c/key.c new file mode 100644 index 0000000..74379f6 --- /dev/null +++ b/c/key.c @@ -0,0 +1,18 @@ +#include +int main() { + initscr(); + cbreak(); + noecho(); + + printw("press h to do something, and q to quit.\n"); + + int ch; + while ((ch = getch()) != 'q') { + if (ch == 'h') { + printw("yep thats h\n"); + } + } + + endwin(); + return 0; +} diff --git a/c/ncurses.c b/c/ncurses.c new file mode 100644 index 0000000..4437d18 --- /dev/null +++ b/c/ncurses.c @@ -0,0 +1,18 @@ +#include + +int main() { + initscr(); + start_color(); + + mvprintw(20, 20, "baller"); + + refresh(); + + getch(); + clear(); + mvprintw(10,30, "baller2"); + getch(); + + endwin(); + return 0; +} diff --git a/c/opengl.c b/c/opengl.c new file mode 100644 index 0000000..9504fce --- /dev/null +++ b/c/opengl.c @@ -0,0 +1,26 @@ +#include +#include + +int main() { + glfwInit(); + + GLFWwindow* window = glfwCreateWindow(400, 400, "baller", NULL, NULL); + glfwMakeContextCurrent(window); + + while (!glfwWindowShouldClose(window)) { + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_QUADS); + glVertex2f(-0.5f, -0.5f); + glVertex2f( 0.5f, -0.5f); + glVertex2f( 0.5f, 0.5f); + glVertex2f(-0.5f, 0.5f); + glEnd(); + + glfwSwapBuffers(window); + glfwPollEvents(); + } + + glfwTerminate(); + return 0; +} 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 + +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 + +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/sig.c b/c/sig.c new file mode 100644 index 0000000..53cb721 --- /dev/null +++ b/c/sig.c @@ -0,0 +1,13 @@ +#include +#include +//#include + +void handlesig36(int sig) { + printf("received signal %d\n", sig); +} + +int main() { + signal(SIGRTMIN+2, handlesig36); + //while (1); + 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 +#include + +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/sw.c b/c/sw.c new file mode 100644 index 0000000..9ddc567 --- /dev/null +++ b/c/sw.c @@ -0,0 +1,27 @@ +#include +#include + +int global_hours = 0; +int global_minutes = 0; +int global_seconds = 0; + + +int main() { + for (int hours = 0; hours < 99; hours += 1) { + for (int minutes = 0; minutes < 60; minutes += 1) { + for (int seconds = 0; seconds < 60; seconds += 1) { + sleep(1); + global_seconds++; + printf("%d:", global_hours); + printf("%d:", global_minutes); + printf("%d\n", global_seconds); + } + global_seconds = 0; + global_minutes++;; + } + global_minutes = 0; + global_hours++; + } + 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 +#include +#include +#include +#include +#include + +// 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); +} -- cgit v1.2.3