diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-05-24 12:58:39 +0100 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-05-24 12:58:39 +0100 |
commit | 5bbcb1f542c239ce1e9b5a7d3c7214a7bf001d6a (patch) | |
tree | 47ef91ea74fc60660d79b87ec00f8f25d6366722 | |
parent | 420ef6622d9e8de96ffc1843b9b4c3c3ea87b1c9 (diff) | |
download | c-stuff-5bbcb1f542c239ce1e9b5a7d3c7214a7bf001d6a.tar.gz c-stuff-5bbcb1f542c239ce1e9b5a7d3c7214a7bf001d6a.tar.xz c-stuff-5bbcb1f542c239ce1e9b5a7d3c7214a7bf001d6a.zip |
More random stuff.
-rw-r--r-- | rot.c | 26 | ||||
-rw-r--r-- | split3.c | 76 | ||||
-rw-r--r-- | vectest.c | 11 | ||||
-rw-r--r-- | xlib-testing.c | 40 |
4 files changed, 153 insertions, 0 deletions
@@ -0,0 +1,26 @@ +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <stdlib.h> + +#define mod(A) ((A)%26) + +int main(int argc, char **argv) +{ + if(argc!=3) + exit(1); + char *string = *(argv+1); + int i, rot = (int)strtol(*(argv+2), NULL, 10); + for(i=0; i<strlen(string); i++) + if(isalpha(string[i])){ + if(string[i]-'A'<26){ // Simple way to differentiate lower and upper case if all letters are known to be alpha. + putchar(mod(string[i]-'A'+rot)+'A'); + }else{ + putchar(mod(string[i]-'a'+rot)+'a'); + } + }else{ + putchar(string[i]); + } + putchar('\n'); + return 0; +} diff --git a/split3.c b/split3.c new file mode 100644 index 0000000..7f2fc18 --- /dev/null +++ b/split3.c @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <ctype.h> +#include <stdlib.h> +#include <string.h> + +int *genccountdict(char *); +char *nodup(char *, int *); +char *nnodup(char *, int *); +char *dup(char *, int *); + +int main(int argc, char **argv) +{ + int i; + if(argc!=2) + exit(1); + + char *string = *(argv+1); + int *dict = genccountdict(string); + + for(i = 0; i < strlen(string); i++) + string[i] = toupper(string[i]); + + printf("nodup: %s\n", nodup(string, dict)); + printf("nnodup: %s\n", nnodup(string, dict)); + printf("dup: %s\n", dup(string, dict)); + return 0; +} + +int *genccountdict(char *input) +{ + int *dict = calloc(sizeof(int), 26); + int i; + for(i=0; i<strlen(input); i++) + if(isalpha(input[i])) + dict[toupper(input[i])-'A']++; + return dict; +} + +char *nodup(char *input) +{ + char *output = malloc(strlen(input)+1); + 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; + } + } + output[outpt]='\0'; + return output; +} + +char *nnodup(char *input, int *dict) +{ + char *output = malloc(strlen(input)+1); + int i, outpt = 0; + for(i=0; i<strlen(input); i++) + if(dict[input[i]-'A']==1) + output[outpt++]=input[i]; + output[outpt]='\0'; + return output; +} + +char *dup(char *input, int *dict) +{ + char *output = malloc(strlen(input)+1); + int i, outpt = 0; + for(i=0; i<strlen(input); i++) + if(dict[input[i]-'A']>1) + output[outpt++]=input[i]; + output[outpt] = '\0'; + int ndict[26]; + memset(ndict, 0, 26*sizeof(int)); + return nodup(output, ndict); +} diff --git a/vectest.c b/vectest.c new file mode 100644 index 0000000..042bc28 --- /dev/null +++ b/vectest.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdlib.h> +#include <vecmat/vec.h> + +int main(int argc, char **argv) +{ + Vec *v = vec_new(123, 12.1, 45); + char *s = malloc(50); + vec_tostring(s, v); + printf(s); +} diff --git a/xlib-testing.c b/xlib-testing.c new file mode 100644 index 0000000..cfb35c0 --- /dev/null +++ b/xlib-testing.c @@ -0,0 +1,40 @@ +#include <X11/Xlib.h> +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + Display *d = XOpenDisplay(NULL); + if (!d) { + fprintf(stderr, "Could not open display."); + exit(1); + } + + unsigned long int black = BlackPixel(d, DefaultScreen(d)); + unsigned long int white = WhitePixel(d, DefaultScreen(d)); + + Window w = XCreateSimpleWindow(d, DefaultRootWindow(d), 0, 0, 300, 300, 0, black, white); + + XSelextInput(d, w, StructureNotifyMask); + + XMapWindow(d, w); + + GC gc = XCreateGC(d, w, 0, NULL); + + XSetForeground(d, gc, white); + + while(1) { + XEvent e; + XNextEvent(d, &e); + if (e.type == MapNotify) + break; + } + + XDrawLine(d, w, gc, 10, 60, 180, 20); + + XFlush(d); + + sleep(10); + + XCloseDisplay(d); +} |