summaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/baller.h1
-rw-r--r--c/bungus.c5
-rw-r--r--c/calculator.c10
-rw-r--r--c/factorial.c18
-rw-r--r--c/float.c11
-rw-r--r--c/head.c7
-rw-r--r--c/key.c18
-rw-r--r--c/ncurses.c18
-rw-r--r--c/opengl.c26
-rw-r--r--c/pointers.c9
-rw-r--r--c/print.c11
-rw-r--r--c/sig.c13
-rw-r--r--c/structs.c49
-rw-r--r--c/sw.c27
-rw-r--r--c/webserver.c29
15 files changed, 252 insertions, 0 deletions
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 <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/factorial.c b/c/factorial.c
new file mode 100644
index 0000000..4ee0720
--- /dev/null
+++ b/c/factorial.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+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 <stdio.h>
+#include <float.h>
+
+// 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 <stdio.h>
+#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 <ncurses.h>
+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 <ncurses.h>
+
+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 <GLFW/glfw3.h>
+#include <stdio.h>
+
+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 <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/sig.c b/c/sig.c
new file mode 100644
index 0000000..53cb721
--- /dev/null
+++ b/c/sig.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <signal.h>
+//#include <unistd.h>
+
+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 <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/sw.c b/c/sw.c
new file mode 100644
index 0000000..9ddc567
--- /dev/null
+++ b/c/sw.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <unistd.h>
+
+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 <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);
+}