Guest User

Fuck strings in C

a guest
Jun 14th, 2015
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. typedef unsigned int uint;
  7.  
  8. typedef unsigned char bool;
  9. #define true 1
  10. #define false 0
  11.  
  12. #define write(buf, str, pos, affect_pos) { \
  13.     uint l = strlen(str); \
  14.     for(uint i=0;i<l;i++) { \
  15.         buf[pos+i]=str[i]; \
  16.     } \
  17.     if(affect_pos) { \
  18.         pos += l; \
  19.     }}
  20. char* join_args(char* strings[], char* seperator, int count) {
  21.     char* str = NULL;
  22.     size_t total_length = 0;
  23.     int i = 0;
  24.     for (i = 0; i < count; i++) total_length += strlen(strings[i]);
  25.     total_length++;
  26.     total_length += strlen(seperator) * (count - 1);
  27.     str = (char*) malloc(total_length);
  28.     str[0] = '\0';
  29.     for (i = 1; i < count; i++) {
  30.         strcat(str, strings[i]);
  31.         if (i < (count - 1)) strcat(str, seperator);
  32.     }
  33.     return str;
  34. }
  35. int main(int arg_count, char* args[]) {
  36.     uint buf_size = 2;
  37.     char* arg_s = join_args(args,"",arg_count);
  38.     uint len = strlen(arg_s);
  39.     for(uint i=0;i<len;i++) {
  40.         char c = arg_s[i];
  41.         if(!isdigit(c)) {
  42.             fputs("Usage: kek (numbers)\n", stderr);
  43.             return 1;
  44.         }
  45.         if(c=='1') {
  46.             buf_size+=2;
  47.         } else if(c=='3'||c=='7') {
  48.             buf_size+=3;
  49.         } else {
  50.             buf_size+=4;
  51.         }
  52.     }
  53.     uint pos=0;
  54.     char line_one[buf_size];
  55.     char line_two[buf_size];
  56.     char line_thr[buf_size];
  57.     for(uint i=0;i<buf_size;i++) {
  58.         line_one[i]=' ';
  59.         line_two[i]=' ';
  60.         line_thr[i]=' ';
  61.     }
  62.     for(uint i=0;i<len;i++) {
  63.         char c = arg_s[i];
  64.         if(c=='0') {
  65.             write(line_one, " _  ", pos, false);
  66.             write(line_two, "| | ", pos, false);
  67.             write(line_thr, "|_| ", pos, true);
  68.         } else if(c=='1') {
  69.             write(line_one, "  ", pos, false);
  70.             write(line_two, "| ", pos, false);
  71.             write(line_thr, "| ", pos, true);
  72.         } else if(c=='2') {
  73.             write(line_one, " _  ", pos, false);
  74.             write(line_two, " _| ", pos, false);
  75.             write(line_thr, "|_  ", pos, true);
  76.         } else if(c=='3') {
  77.             write(line_one, "_  ", pos, false);
  78.             write(line_two, "_| ", pos, false);
  79.             write(line_thr, "_| ", pos, true);
  80.         } else if(c=='4') {
  81.             write(line_one, "    ", pos, false);
  82.             write(line_two, "|_| ", pos, false);
  83.             write(line_thr, "  | ", pos, true);
  84.         } else if(c=='5') {
  85.             write(line_one, " _  ", pos, false);
  86.             write(line_two, "|_  ", pos, false);
  87.             write(line_thr, " _| ", pos, true);
  88.         } else if(c=='6') {
  89.             write(line_one, " _  ", pos, false);
  90.             write(line_two, "|_  ", pos, false);
  91.             write(line_thr, "|_| ", pos, true);
  92.         } else if(c=='7') {
  93.             write(line_one, "_  ", pos, false);
  94.             write(line_two, " | ", pos, false);
  95.             write(line_thr, " | ", pos, true);
  96.         } else if(c=='8') {
  97.             write(line_one, " _  ", pos, false);
  98.             write(line_two, "|_| ", pos, false);
  99.             write(line_thr, "|_| ", pos, true);
  100.         } else if(c=='9') {
  101.             write(line_one, " _  ", pos, false);
  102.             write(line_two, "|_| ", pos, false);
  103.             write(line_thr, " _| ", pos, true);
  104.         }
  105.     }
  106.     line_one[buf_size-1] = 0;
  107.     line_two[buf_size-1] = 0;
  108.     line_thr[buf_size-1] = 0;
  109.     puts(line_one);
  110.     puts(line_two);
  111.     puts(line_thr);
  112. }
  113. /*
  114.  Anonymous  ⋯  EzMake  Projects  kek  bin/kek 42069
  115.      _   _   _   _  
  116. |_|  _| | | |_  |_|  
  117.   | |_  |_| |_|  _|  
  118.  Anonymous  ⋯  EzMake  Projects  kek  
  119. */
Advertisement
Add Comment
Please, Sign In to add comment