diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-05-24 13:05:18 +0100 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-05-24 13:05:18 +0100 |
commit | 39c3721ca16d2dfdbd8e5488e7d1f57a6d54310e (patch) | |
tree | fcec9d101136a5b004ffc3fc1cc6a66dc848a6e5 | |
parent | 5bbcb1f542c239ce1e9b5a7d3c7214a7bf001d6a (diff) | |
parent | a530bad7a6ea2778129db0dc26c446d9f6df6ddd (diff) | |
download | c-stuff-39c3721ca16d2dfdbd8e5488e7d1f57a6d54310e.tar.gz c-stuff-39c3721ca16d2dfdbd8e5488e7d1f57a6d54310e.tar.xz c-stuff-39c3721ca16d2dfdbd8e5488e7d1f57a6d54310e.zip |
Merge branch 'master' of https://github.com/EliteTK/c-stuff
Merge
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | arraytest.c | 10 | ||||
-rw-r--r-- | bff.c | 111 | ||||
-rw-r--r-- | birken.c | 49 | ||||
-rw-r--r-- | box.c | 10 | ||||
-rw-r--r-- | cable1.c | 3 | ||||
-rw-r--r-- | colourconv.c | 17 | ||||
-rw-r--r-- | compressc.c | 5 | ||||
-rw-r--r-- | cursor_remove.c | 6 | ||||
-rw-r--r-- | emevent.c | 30 | ||||
-rw-r--r-- | encrypt.c | 10 | ||||
-rw-r--r-- | example.c | 25 | ||||
-rw-r--r-- | example_comp_man.c | 3 | ||||
-rw-r--r-- | fbcopy.c | 21 | ||||
-rw-r--r-- | foursquare.c | 121 | ||||
-rw-r--r-- | framebuffer.c | 51 | ||||
-rw-r--r-- | genkeypairs.c | 32 | ||||
-rw-r--r-- | gtk.c | 79 | ||||
-rw-r--r-- | helw.c | 5 | ||||
-rw-r--r-- | mevent.c | 26 | ||||
-rw-r--r-- | monty-hall.c | 34 | ||||
-rw-r--r-- | revlist.c | 31 | ||||
-rw-r--r-- | sizes.c | 5 | ||||
-rw-r--r-- | sleep.c | 12 | ||||
-rw-r--r-- | sofbcode.c | 66 | ||||
-rw-r--r-- | vixus.c | 41 | ||||
-rw-r--r-- | weird.c | 6 | ||||
-rw-r--r-- | xlibtest.c | 59 |
28 files changed, 861 insertions, 8 deletions
@@ -1,2 +1,3 @@ * !*.c +!*.h diff --git a/arraytest.c b/arraytest.c new file mode 100644 index 0000000..aed3fe3 --- /dev/null +++ b/arraytest.c @@ -0,0 +1,10 @@ +#include<stdio.h> + +int main(int argc, const char *argv[]) { + char *ptr = &main; + int i; + for (i = 0;; i++) { + putchar(*(ptr+i)); + } + return 0; +} @@ -0,0 +1,111 @@ +// Generated with TK's "fuck" brainfuck to C parser. +#include<stdio.h> +#include<stdlib.h> + +int main() { + char *ptrt; + ptrt = calloc(1000, sizeof(char)); + char *ptr; + ptr = ptrt; + // The following is directly parsed + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + while (*ptr) { + ++ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + --ptr; + --ptr; + --*ptr; + } + ++ptr; + --*ptr; + --*ptr; + --*ptr; + putchar(*ptr); + ++ptr; + ++*ptr; + putchar(*ptr); + --*ptr; + --*ptr; + --*ptr; + putchar(*ptr); + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + --*ptr; + putchar(*ptr); + --*ptr; + --*ptr; + putchar(*ptr); + --ptr; + putchar(*ptr); + ++ptr; + ++ptr; + ++*ptr; + ++*ptr; + ++*ptr; + while (*ptr) { + --*ptr; + --ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++ptr; + } + --ptr; + ++*ptr; + putchar(*ptr); + --*ptr; + --*ptr; + --*ptr; + putchar(*ptr); + --*ptr; + --*ptr; + --*ptr; + putchar(*ptr); + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + ++*ptr; + putchar(*ptr); + // Closing cleanup + free(ptrt); + putchar('\n'); + return 0; +} diff --git a/birken.c b/birken.c new file mode 100644 index 0000000..a65d9f9 --- /dev/null +++ b/birken.c @@ -0,0 +1,49 @@ +char*_ = "'""/*"; +#include <stdio.h> +#define m 21 +#define o(l, k) for(l=0; l<k; l++) +#define n(k) o(T, k) + + + int E,L,O,R,G[42][m],h[2][42][m],g[3][8],c + [42][42][2],f[42]; char d[42]; void v( int + b,int a,int j){ printf("\33[%d;%df\33[4%d" + "m ",a,b,j); } void u(){ int T,e; n(42)o( + e,m)if(h[0][T][e]-h[1][T][e]){ v(e+4+e,T+2 + ,h[0][T][e]+1?h[0][T][e]:0); h[1][T][e]=h[ + 0][T][e]; } fflush(stdout); } void q(int l + ,int k,int p){ + int T,e,a; L=0 + ; O=1; while(O + ){ n(4&&L){ e= + k+c[l] [T][0]; + h[0][L-1+c[l][ + T][1]][p?20-e: +e]=-1; } n(4){ e=k+c[l][T][0]; a=L+c[l][T][ +1]+1; if(a==42 || h[0][a][p?20-e:e]+1){ O=0 +; } } n(4){ e= k+c[l][T][0]; h[0][L + c[l][ +T][1]][p?20-e: e]=g[1][f[p?19+l:l]]; } L++; +u(); } n(42) { o(e,m)if(h[0][T][e]<0)break; +o(a, m&&e==m){ for(L=T; L; L--) { h[0][L][a +]=h[0][L-1] [a ]; } h[0][0][a]=-1; } } u(); +}int main(){ int T,e,t,r,i,s ,D,V,K; printf("\33[2J\33[?25l"); n(8)g[i= +1][T]=7-T; R--; n(42) o(e,m) G[T][e]--; while(fgets(d,42,stdin)) { r=++ +R; n(17){ e=d[T]-48; d[T]=0; if ((e&7)==e) { g[0][e] ++; G[R][T+2]=e; } +} } n(8)if(g[0][7-T]){ t=g[i ][O]; g[i][O++]=g[i][T]; g[i][T]=t; } n(8) +g[2][g[i][T]]=T; n(R+i)o(e,m )if(G[T][e]+i) G[T][e]=g[2][G[T][e]]; n(19 +)o(t,2){ f[T+t+T]=(T["+%#,4" "5>GP9$5-,#C?NX"]-35)>>t*3&7; o(e,4){ c[T] +[e][t]=("5'<$=$8)Ih$=h9i8'9" "t=)83)l4(99(g9>##>4(" [T+t+T]-35)>>e*2&3; +} } n(15) { s=T>9?m:(T&3)-3?15:36;o(e,s)o(t,2)c[T+19][e][t]="6*6,8*6.608.6264826668\ +865::(+;0(6+6-6/8,61638065678469.;88))()3(6,8*6.608.6264826668865:+;4)-*6-6/616365,\ +-6715690.5;,89,81+,(023096/:40(8-7751)2)65;695(855(+*8)+;4**+4(((6.608.626482666886\ +5:+;4+4)0(8)6/61638065678469.;88)-4,4*8+4(((60(/6264826668865:+;4-616365676993-9:54\ ++-14).;./347.+18*):1;-*0-975/)936.+:4*,80987(887(0(*)4.*""/4,4*8+4(((6264826668865:\ ++;4/4-4+8-4)0(8)6365678469.;88)1/(6*6,6.60626466686:8)8-8*818.8582/9863(+;/""*6,6.6\ +0626466686:4(8)8-8*818.8582/9863(+;/,6.60626466686:8-818.8582/9864*4+4(0())+;/.6062\ +6466686:8/8380/7844,4-4*4+4(0())69+;/0626466686:818582/9864.4/4,4-4*4+4(0())+;" [e+E ++e+t]-40; E+=s+s; } n(45){ if(T>i) { v(2,T,7); v(46,T,7); } v(2+T,44,7); } T=0; o(e, +42)o(t,m)h[T][e][t]--; while(R+i) { s = D=0; if (r-R) { n(19) if (G[R+i][T]+i) V=T/2 +; else if(G[R][T]+i) s++; if(s) { if(V>4){ V=9-V; D++; } V+=29; n(20) q(c[V][T][0],c +[V][T][i],D); } } n(19) if((L=G[R][T])+i) { O=T-L; e=O>9; t=e?18-O :O; o(K,((t&3)-3? +16:37)){ if(K){ L=c[t+19][K-i][0]; O=c[t+19][K-i][i] ; } q(L,O,K && e); } } if(s) q( +c[V][20][0], c[V][20][i], D); R--; } printf("\33[47;1f\33[?25h\33[40m"); return 0; } @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main(int argc, char **argv) +{ + if(argc != 2){ + printf("\33[?25l"); + } else { + printf("\33[?25h"); + } +} diff --git a/cable1.c b/cable1.c new file mode 100644 index 0000000..eea13dc --- /dev/null +++ b/cable1.c @@ -0,0 +1,3 @@ +main(int argc, char**argv) {
+ puts( 1[argv - ~ !(*(int*) 1[argv]%4796%275%argc ) ] );
+}
diff --git a/colourconv.c b/colourconv.c new file mode 100644 index 0000000..4863c77 --- /dev/null +++ b/colourconv.c @@ -0,0 +1,17 @@ +#include<stdio.h> + +int main( int argc, char *argv[] ) { + if ( argc != 5 ) { + printf("Usage %s <red> <green> <blue> <alpha>\n", argv[0]); + return 1; + } + + unsigned char red = atoi( argv[1] ); + unsigned char green = atoi( argv[2] ); + unsigned char blue = atoi( argv[3] ); + unsigned char alpha = atoi( argv[4] ); + + unsigned int colour = alpha << 24 | red << 16 | green << 8 | blue; + + printf("R: %u G: %u B: %u A: %u\nColour value: %u\n", red , green, blue, alpha, colour); +} diff --git a/compressc.c b/compressc.c new file mode 100644 index 0000000..e8f0f63 --- /dev/null +++ b/compressc.c @@ -0,0 +1,5 @@ +#include<stdio.h> + +int main(void) { + printf("WIP\n"); +} diff --git a/cursor_remove.c b/cursor_remove.c new file mode 100644 index 0000000..a413709 --- /dev/null +++ b/cursor_remove.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(int argc, char **argv) +{ + printf("\33[8m"); +} diff --git a/emevent.c b/emevent.c new file mode 100644 index 0000000..0c086b1 --- /dev/null +++ b/emevent.c @@ -0,0 +1,30 @@ +#include <stdio.h> + +#define EVLEN 24 + +int main(int argc, char **argv) +{ + int i, c[24], last[8], diff; + while(1){ + while(1){ + for(i=0; i<EVLEN; i++) + c[i] = getchar(); + + putchar('\n'); + for(i=0; i<8; i++) + if(c[8+i] != last[i]){ + diff = 1; + last[i] = c[8+i]; + } + + if(diff){ + printf("---- EVENT ----\n"); + diff = 0; + } + + for(i=0; i<EVLEN; i++) + printf("%2x", c[i]); + } + } + return 0; +} diff --git a/encrypt.c b/encrypt.c new file mode 100644 index 0000000..6a8ca12 --- /dev/null +++ b/encrypt.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + srand(time(NULL)); + char c; + while((c = getchar()) != EOF) + putchar((char)((double)rand() / (double)RAND_MAX * (double)256)); +} diff --git a/example.c b/example.c new file mode 100644 index 0000000..e643da5 --- /dev/null +++ b/example.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <stdlib.h> + +struct test { + int number; + char letter; + char *string; +}; + +void printstruct( const struct test * ); + +int main( int argc, char *argv[] ) { + struct test cake; + cake.number = 5; + cake.letter = 'a'; + cake.string = "Magic"; + + printstruct( &cake ); + return 0; +} + +void printstruct( const struct test * testp ) { + printf("Number: %d\nLetter: %c\nString: %s\n", testp->number, testp->letter, testp->string); + return; +} diff --git a/example_comp_man.c b/example_comp_man.c new file mode 100644 index 0000000..b6845e6 --- /dev/null +++ b/example_comp_man.c @@ -0,0 +1,3 @@ +#include <stdio.h> +#include <stdlib.h> +struct test{int number;char letter;char *string;};void printstruct(const struct test*);int main(int argc,char*argv[]){struct test cake;cake.number=5;cake.letter='a';cake.string="Magic";printstruct(&cake);return 0;}void printstruct(const struct test*testp){printf("Number: %d\nLetter: %c\nString: %s\n",testp->number,testp->letter,testp->string);return;} diff --git a/fbcopy.c b/fbcopy.c new file mode 100644 index 0000000..bc4e078 --- /dev/null +++ b/fbcopy.c @@ -0,0 +1,21 @@ +#include<stdio.h> +#include<stdlib.h> +#include<time.h> + +int main(void) { + FILE *fbp = fopen( "/dev/fb0", "r" ); + if (!fbp) + exit(1); + puts("Opened framebuffer for reading."); + FILE *outfile = fopen( "/home/main/c-stuff/fbshot", "w" ); + if (!outfile) + exit(1); + puts("Opened outfile for writing."); + char c; + while ( (c = fgetc(fbp)) != EOF ) + fputc(c, outfile); + puts("Finished writing to files. Closing."); + fclose(fbp); + fclose(outfile); + puts("Finished."); +} diff --git a/foursquare.c b/foursquare.c new file mode 100644 index 0000000..9552ed4 --- /dev/null +++ b/foursquare.c @@ -0,0 +1,121 @@ +// foursquare.c +#include <stdio.h> +#include <ctype.h> +#include <stdlib.h> +#include <string.h> + +#define Q ('Q'-'A') + +typedef struct vec2 { + int x; + int y; +} Vec2; + +int increinc(int *); +void allupper(char *); +void genkey(char *, char *); +Vec2 *newVec2(const int, const int); + +int main(int argc, char **argv) +{ + int x, y, c=0; + + if(argc!=4){ + printf("Usage: %s <key1> <key2> <cipher>", *argv); + exit(1); + } + + printf("%s, %s ", *(argv+1), *(argv+2)); + + char *trkey = *(argv+1); + allupper(trkey); + char *trfullkey = malloc(26); + genkey(trkey, trfullkey); + + char *blkey = *(argv+2); + allupper(blkey); + char *blfullkey = malloc(26); + genkey(blkey, blfullkey); + + char *cipher = *(argv+3); + allupper(cipher); + + int i=0; + Vec2 *trtable[25]; + for(x=0; x<5; x++) + for(y=0; y<5; y++) + trtable[trfullkey[i++]-'A'] = newVec2(x, y); + free(trfullkey); + + i = 0; + Vec2 *bltable[25]; + for(x=0; x<5; x++) + for(y=0; y<5; y++) + bltable[blfullkey[i++]-'A'] = newVec2(x, y); + free(blfullkey); + + char basetable[5][5]; + for(x=0; x<5; x++) + for(y=0; y<5; y++){ + if(c==Q) + c++; + basetable[x][y] = 'A' + c++; + } + + for(i=0; i<strlen(cipher)/2; i++){ + char c1 = cipher[2*i]; + char c2 = cipher[2*i+1]; + + putchar(basetable[trtable[c1-'A']->x][bltable[c2-'A']->y]); + putchar(basetable[bltable[c2-'A']->x][trtable[c1-'A']->y]); + } + putchar('\n'); + + for(i=0; i++; i<25){ + free(trtable[i]); + free(bltable[i]); + } + + return 0; +} + +int increinc(int *num) +{ + (*num)++; + return (*num)++; +} + +void allupper(char *input) +{ + int i; + for(i=0; i<strlen(input); i++) + if(isalpha(input[i])) + input[i]=toupper(input[i]); +} + +void genkey(char *input, char *output) +{ + int dict[26]; + memset(dict, 0, 26*sizeof(int)); + + int i, outpt = 0; + for(i=0; i<strlen(input); i++){ + if(!dict[input[i]-'A']){ + output[outpt++]=input[i]; + } + dict[input[i]-'A'] += 1; + } + + for(i=0; i<26; i++) + if(!dict[i] && i!=Q) + output[outpt++]=i+'A'; + output[outpt]='\0'; +} + +Vec2 *newVec2(const int x, const int y) +{ + Vec2 *v = malloc(sizeof(Vec2)); + v->x = x; + v->y = y; + return v; +} diff --git a/framebuffer.c b/framebuffer.c index 9902fa1..6eab853 100644 --- a/framebuffer.c +++ b/framebuffer.c @@ -1,14 +1,49 @@ #include<stdio.h> #include<stdlib.h> +#define SSIZE 3145728 +#define INFILE "/home/main/c-stuff/fbshot" + int main( void ) { - printf("Here goes nothing!"); - getchar(); - FILE *fbp = fopen( "/dev/fb0", "w"); - int i; - for( i = 0; i < 1044480; i++ ) - fputc(i, fbp); - fclose( fbp ); -} + FILE *fbp = fopen( "/dev/fb0", "w" ); + if (!fbp) { + puts("Failed to open /dev/fb0"); + exit(1); + } + FILE *infile = fopen( INFILE, "r" ); + if (!infile) { + printf("Failed to open %s\n", INFILE); + exit(1); + } + int i, ii, iii; + for ( iii = 0; iii < 768 / 3; iii++ ) { + for ( i = 0; i < 1024; i++ ) { + fputc(255, fbp); + fputc(0, fbp); + fputc(0, fbp); + fputc(255, fbp); + } + for ( i = 0; i < 1024; i++ ) { + fputc(0, fbp); + fputc(255, fbp); + fputc(0, fbp); + fputc(255, fbp); + } + for ( i = 0; i < 1024; i++ ) { + fputc(0, fbp); + fputc(0, fbp); + fputc(255, fbp); + fputc(255, fbp); + } + } + + /* + char c; + while((c = fgetc(infile)) != EOF) + fputc(c, fbp); + */ + fclose( fbp ); + fclose( infile ); +} diff --git a/genkeypairs.c b/genkeypairs.c new file mode 100644 index 0000000..df4bc3d --- /dev/null +++ b/genkeypairs.c @@ -0,0 +1,32 @@ +// genkeypairs.c +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAXLIST 1000 +#define MAXKEY 100 + +int main(int argc, char **argv) +{ + int c, i, ii, listsize; + char *list[MAXLIST]; + char *word = malloc(MAXKEY+1); + for(i=0; i<MAXLIST; i++) + if(!getword(word, MAXKEY)) + break; + else + memcpy(list[i]=malloc(strlen(word)+1), word, strlen(word)+1); + listsize = ++i; + for(i=0; i<listsize; i++) + for(ii=i+1; ii<listsize-1; ii++) + printf("./justkeys %s %s\n", list[i], list[ii]); +} + +int getword(char *output, int maxlength) +{ + int c, p=0; + while((c=getchar())!=EOF && isalpha(c) && p<maxlength) + output[p++] = (char)c; + output[p] = '\0'; + return p; +} @@ -0,0 +1,79 @@ +#include<gtk/gtk.h> + +gint count = 0; +char buf[5]; + +void increase(GtkWidget *widget, gpointer label) +{ + count++; + + sprintf(buf, "%d", count); + gtk_label_set_text(GTK_LABEL(label), buf); +} + +void decrease(GtkWidget *widget, gpointer label) +{ + count--; + + sprintf(buf, "%d", count); + gtk_label_set_text(GTK_LABEL(label), buf); +} + + +GdkPixbuf *create_pixbuf(const gchar *filename) +{ + GdkPixbuf *pixbuf; + GError *error = NULL; + pixbuf = gdk_pixbuf_new_from_file(filename, &error); + if(!pixbuf) { + fprintf(stderr, "%s\n", error->message); + g_error_free(error); + } + + return pixbuf; +} + +int main(int argc, char **argv) +{ + + GtkWidget *label; + GtkWidget *window; + GtkWidget *frame; + GtkWidget *plus; + GtkWidget *minus; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), "Yay!"); + gtk_window_set_default_size(GTK_WINDOW(window), 250, 180); + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); + gtk_window_set_icon(GTK_WINDOW(window), create_pixbuf("/home/main/Media/Pictures/GTKTutIcon.png")); + + frame = gtk_fixed_new(); + gtk_container_add(GTK_CONTAINER(window), frame); + + plus = gtk_button_new_with_label("+"); + gtk_widget_set_size_request(plus, 50, 20); + gtk_fixed_put(GTK_FIXED(frame), plus, 50, 20); + + minus = gtk_button_new_with_label("-"); + gtk_widget_set_size_request(minus, 50, 20); + gtk_fixed_put(GTK_FIXED(frame), minus, 50, 80); + + label = gtk_label_new("0"); + gtk_fixed_put(GTK_FIXED(frame), label, 190, 58); + + gtk_widget_show_all(window); + + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); + + g_signal_connect(plus, "clicked", G_CALLBACK(increase), label); + + g_signal_connect(minus, "clicked", G_CALLBACK(decrease), label); + + gtk_main(); + + return 0; +} + @@ -0,0 +1,5 @@ +#include<stdio.h> +int main(void) { + printf("Hello World!"); + return 0; +} diff --git a/mevent.c b/mevent.c new file mode 100644 index 0000000..4fd176a --- /dev/null +++ b/mevent.c @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <stdlib.h> + +#define B2BP "%d%d%d%d%d%d%d%d" +#define B2B(byte) \ + (byte & 0x80 ? 1 : 0), \ + (byte & 0x40 ? 1 : 0), \ + (byte & 0x20 ? 1 : 0), \ + (byte & 0x10 ? 1 : 0), \ + (byte & 0x08 ? 1 : 0), \ + (byte & 0x04 ? 1 : 0), \ + (byte & 0x02 ? 1 : 0), \ + (byte & 0x01 ? 1 : 0) + +int main(int argc, char **argv) +{ + signed char *c=malloc(3*sizeof(char)), i; + while(1){ + for(i=0; i<3; i++) + c[i] = getchar(); + printf("%2x %2x %2x ", (unsigned char)c[0], (unsigned char)c[1], (unsigned char)c[2]); + printf(": "B2BP B2BP B2BP" ", B2B(c[0]), B2B(c[1]), B2B(c[2])); + printf(": %d %d %d\n", (signed char)c[0], (signed char)c[1], (signed char)c[2]); + } + return 0; +} diff --git a/monty-hall.c b/monty-hall.c new file mode 100644 index 0000000..7ab6a2c --- /dev/null +++ b/monty-hall.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define ITERATIONS 1000 + +int main(int argc, char **argv) +{ + srand(time(NULL)); + + int i, won = 0, lost = 0, opt, winopt, discard; + for(i = 0; i<ITERATIONS; i++){ + opt = (float)rand() / (float)RAND_MAX * 3.0; + winopt = (float)rand() / (float)RAND_MAX * 3.0; + if(opt == winopt){ + discard = (float)rand() / (float)RAND_MAX * 2.0; + if(!opt) + discard +=1; + else if(opt == 1 && discard) + discard = 2; + }else{ + discard = 3 - opt - winopt; + } + opt = 3 - opt - discard; + + if(opt == winopt) + won++; + else + lost++; + } + + printf("Won: %d, Lost: %d.\n", won, lost); + return 0; +} diff --git a/revlist.c b/revlist.c new file mode 100644 index 0000000..4c5dddb --- /dev/null +++ b/revlist.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + if(argc != 3){ + fprintf(stderr, "Incorrect argument count.\nUsage: %s <string> <separator>\n"\ + , argv[0]); + exit(1); + } + + char *input = argv[1]; + char separator = argv[2][0]; + int length = strlen(input), startpos = 0, strpos; + + char *output = malloc(length); + + for(strpos = 0; strpos <= length; strpos ++){ + if(input[strpos] == separator || strpos == length){ + strncpy(output + length - strpos, input + startpos, strpos - startpos); + if(strpos != length) + output[length - strpos - 1] = separator; + startpos = strpos + 1; + } + } + + printf("%s\n", output); + free(output); + return 0; +} @@ -0,0 +1,5 @@ +#include<stdio.h> + +int main( int argc, char *argv[] ) { + printf("%d\n", sizeof(long *)); +} @@ -0,0 +1,12 @@ +#include<stdio.h> +#include<stdlib.h> + +int main(void) { + printf("This is before the sleep.\n"); + sleep(10); + printf("This is after the sleep and before the for loop.\n"); + long i; + for(i = 0; i < 999999999999999; i++) + ; + printf("This is after the for loop.\n"); +} diff --git a/sofbcode.c b/sofbcode.c new file mode 100644 index 0000000..e4b9d3d --- /dev/null +++ b/sofbcode.c @@ -0,0 +1,66 @@ +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <linux/fb.h> +#include <sys/mman.h> + +int main() +{ + int fbfd = 0; + struct fb_var_screeninfo vinfo; + struct fb_fix_screeninfo finfo; + long int screensize = 0; + char *fbp = 0; + int x = 0, y = 0; + long int location = 0; + int count ; + + /* Open the file for reading and writing */ + fbfd = open("/dev/fb0", O_RDWR); + if (!fbfd) { + printf("Error: cannot open framebuffer device.\n"); + exit(1); + } + printf("The framebuffer device was opened successfully.\n"); + /* Get fixed screen information */ + if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { + printf("Error reading fixed information.\n"); + exit(2); + } + + /* Get variable screen information */ + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { + printf("Error reading variable information.\n"); + exit(3); + } + + /* Figure out the size of the screen in bytes */ + screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; + printf("\nScreen size is %d",screensize); + printf("\nVinfo.bpp = %d",vinfo.bits_per_pixel); + + /* Map the device to memory */ + fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,fbfd, 0); + if ((int)fbp == -1) { + printf("Error: failed to map framebuffer device to memory.\n"); + exit(4); + } + printf("The framebuffer device was mapped to memory successfully.\n"); + + + x = 100; y = 100; /* Where we are going to put the pixel */ + + /* Figure out where in memory to put the pixel */ + location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length; + for(count = 1 ;count < 100 ;count++) + { + *(fbp + location) = 255; /* Some blue */ + *(fbp + location + count) = 0; /* A little green */ + *(fbp + location + count + 1) = 0; /* A lot of red */ + *(fbp + location + count + 2) = 0; /* No transparency */ + } + munmap(fbp, screensize); + close(fbfd); + return 0; +} @@ -0,0 +1,41 @@ +#include <X11/Xft/Xft.h> +#include <X11/Xlib.h> +#include <X11/extensions/Xrender.h> +#include <fontconfig/fontconfig.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char** argv) { + if (argc < 3) { + printf("xftwidth font string\n"); + return 1; + } + + Display *dpy; + XftFont *fn; + XGlyphInfo ext; + FcChar8 *str; + + char *name = argv[1]; + size_t len = strlen(argv[2]); +// len + 1?.. + str = (FcChar8*) malloc(len * sizeof(FcChar8) + 1); + + strncpy((char*)str, argv[2], len); + + dpy = XOpenDisplay(NULL); + fn = XftFontOpenName(dpy, 0, name); + + if (fn == NULL) { + printf("Font not found.\n"); + return 1; + } + + XftTextExtents8(dpy, fn, str, (int)len, &ext); + printf("%d\n", ext.width); + + free((void*)str); + return 0; +} @@ -0,0 +1,6 @@ +#include<stdio.h> + +int main(int argc, const char *argv[]) { + printf("%d\n", 1[0]); + return 0; +} diff --git a/xlibtest.c b/xlibtest.c new file mode 100644 index 0000000..adcbd26 --- /dev/null +++ b/xlibtest.c @@ -0,0 +1,59 @@ +/* + * Simple Xlib application drawing a box in a window. + * gcc input.c -o output -lX11 + */ + +#include <X11/Xlib.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char **argv) +{ + Display *display; + Window window; + XEvent event; + char *msg = "Hello, World!"; + int s; + + /* open connection with the server */ + display = XOpenDisplay(NULL); + if (display == NULL) + { + fprintf(stderr, "Cannot open display\n"); + exit(1); + } + + s = DefaultScreen(display); + + /* create window */ + window = XCreateSimpleWindow(display, RootWindow(display, s), 10, 10, 200, 200, 1, + BlackPixel(display, s), WhitePixel(display, s)); + + /* select kind of events we are interested in */ + XSelectInput(display, window, ExposureMask | KeyPressMask); + + /* map (show) the window */ + XMapWindow(display, window); + + /* event loop */ + for (;;) + { + XNextEvent(display, &event); + + /* draw or redraw the window */ + if (event.type == Expose) + { + XFillRectangle(display, window, DefaultGC(display, s), 20, 20, 10, 10); + XDrawString(display, window, DefaultGC(display, s), 50, 50, msg, strlen(msg)); + } + /* exit on key press */ + if (event.type == KeyPress) + break; + } + + /* close connection to server */ + XCloseDisplay(display); + + return 0; +} |