diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-04-24 09:06:24 +0100 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-04-24 09:06:24 +0100 |
commit | a98d134e89a42909721dcefd426118af38628048 (patch) | |
tree | cdf43f11ed4aafbc46fe813584851612ae7c3c89 /revlist.c | |
parent | c1a966057407d815d054ddbd2432badda91d4379 (diff) | |
download | c-stuff-a98d134e89a42909721dcefd426118af38628048.tar.gz c-stuff-a98d134e89a42909721dcefd426118af38628048.tar.xz c-stuff-a98d134e89a42909721dcefd426118af38628048.zip |
Latest random crap.
Diffstat (limited to 'revlist.c')
-rw-r--r-- | revlist.c | 31 |
1 files changed, 31 insertions, 0 deletions
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; +} |