Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
int main(void) {
const char *messages[] = { "%d\n", "Fizz\n", "Buzz\n", "Fizzbuzz\n" };
for (int i = 1; i <= 100; i++)
printf(messages[!(i % 3) | (!(i % 5) << 1)], i);
}
@REPOmAN2v2
REPOmAN2v2 / gist:c3ab203e7cbf2fd2fa47
Created October 24, 2014 19:15
Text input example in SDL
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
@REPOmAN2v2
REPOmAN2v2 / gist:2012b7384bd20a303fc4
Created September 24, 2014 22:56
Array shuffling in C
/* Fisher-Yates shuffle
Assume rand is already seeded */
void shuffle(my_type_t *A, size_t n)
{
int i, j;
my_type_t t;
for (i = n-1; i > 0; i--) {
j = rand() % (i+1) /* random int, 0 <= j <= i */
t = A[i];
float getTime()
{
static uint_least64_t start = 0;
struct timeval tv;
if (start == 0) {
gettimeofday(&tv,NULL);
start = 1000000 * tv.tv_sec + tv.tv_usec;
return 0.0f;
}
@REPOmAN2v2
REPOmAN2v2 / gist:67eb1b4d3c532f1f802a
Created September 3, 2014 09:38
Some ncurses functionality in str8 C
#include <stdio.h> // I/O Junk
#include <stdlib.h> // For rand()
#include <unistd.h> // For usleep()
#include <signal.h> // For Signal handler
#ifdef __linux__
#include <termios.h> // To change term settings (no echo mode)
#elif _WIN32
#include <conio.h>
#else
@REPOmAN2v2
REPOmAN2v2 / gist:5c50ee26a37775dfdd3b
Created August 20, 2014 23:51
Circular double linked list implementation
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
// node structure
typedef struct list_t {
char *value;
struct list_t *next;
#include <stdio.h>
int main (void)
{
int i;
char s[] = " 0123456789";
for (i = 9; i >= 0; i--)
printf("%.10s\n", s + i);
}
int main(void)
{
int frames = 0;
double fpstimer;
double ticktimer = 0.0;
double last;
last = dtime();
while (1) {
double now = getTime();
@REPOmAN2v2
REPOmAN2v2 / gist:4bb1df1553cad7a18126
Last active August 29, 2015 14:01
C array NULL sorting program
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
const void * const t[] = { malloc(1), NULL, malloc(1), NULL, malloc(1)};
const size_t size = sizeof t / sizeof *t;
const void ** it = (const void **) t;
const void * const * const end = (const void **) t + size;
#!/bin/bash
#this is what i am trying in c right now, but i think some of you guys can solve this with a small shell script
#i got the following folder structure:
#reaction pics
#-laughing
#->12321.jpg
#->321312.jpg
#-wat