init
This commit is contained in:
1
c/baller.h
Normal file
1
c/baller.h
Normal file
@ -0,0 +1 @@
|
||||
static char BALLER[] = "baller";
|
||||
5
c/bungus.c
Normal file
5
c/bungus.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("boner\n");
|
||||
}
|
||||
10
c/calculator.c
Normal file
10
c/calculator.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
18
c/factorial.c
Normal file
18
c/factorial.c
Normal file
@ -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;
|
||||
}
|
||||
7
c/head.c
Normal file
7
c/head.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include "baller.h"
|
||||
|
||||
int main() {
|
||||
printf("%s\n", BALLER);
|
||||
return 0;
|
||||
}
|
||||
18
c/key.c
Normal file
18
c/key.c
Normal file
@ -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;
|
||||
}
|
||||
18
c/ncurses.c
Normal file
18
c/ncurses.c
Normal file
@ -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;
|
||||
}
|
||||
26
c/opengl.c
Normal file
26
c/opengl.c
Normal file
@ -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;
|
||||
}
|
||||
9
c/pointers.c
Normal file
9
c/pointers.c
Normal file
@ -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;
|
||||
}
|
||||
11
c/print.c
Normal file
11
c/print.c
Normal file
@ -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;
|
||||
}
|
||||
13
c/sig.c
Normal file
13
c/sig.c
Normal file
@ -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;
|
||||
}
|
||||
49
c/structs.c
Normal file
49
c/structs.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
29
c/webserver.c
Normal file
29
c/webserver.c
Normal file
@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user