aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEliteTK <tomasz.kramkowski@gmail.com>2014-05-05 14:26:29 +0100
committerEliteTK <tomasz.kramkowski@gmail.com>2014-05-05 14:26:29 +0100
commita530bad7a6ea2778129db0dc26c446d9f6df6ddd (patch)
tree8f2f751092046f44a7fbc8bd92f57b013e1483f5
parenta98d134e89a42909721dcefd426118af38628048 (diff)
downloadc-stuff-a530bad7a6ea2778129db0dc26c446d9f6df6ddd.tar.gz
c-stuff-a530bad7a6ea2778129db0dc26c446d9f6df6ddd.tar.xz
c-stuff-a530bad7a6ea2778129db0dc26c446d9f6df6ddd.zip
More stuff.
-rw-r--r--emevent.c30
-rw-r--r--mevent.c26
-rw-r--r--monty-hall.c34
-rw-r--r--sizes.c2
-rw-r--r--xlibtest.c2
5 files changed, 92 insertions, 2 deletions
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/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/sizes.c b/sizes.c
index 19759f7..4393392 100644
--- a/sizes.c
+++ b/sizes.c
@@ -1,5 +1,5 @@
#include<stdio.h>
int main( int argc, char *argv[] ) {
- printf("%d\n", sizeof(long));
+ printf("%d\n", sizeof(long *));
}
diff --git a/xlibtest.c b/xlibtest.c
index 670dcf6..adcbd26 100644
--- a/xlibtest.c
+++ b/xlibtest.c
@@ -8,7 +8,7 @@
#include <stdlib.h>
#include <string.h>
-int main(void)
+int main(int argc, char **argv)
{
Display *display;
Window window;