Pastebin PRO Accounts EASTER SPECIAL! For a limited time only get 40% discount on a LIFETIME PRO account! Offer Ends Soon!
SHARE
TWEET
Fuck strings in C
a guest
Jun 14th, 2015
671
Never
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- typedef unsigned int uint;
- typedef unsigned char bool;
- #define true 1
- #define false 0
- #define write(buf, str, pos, affect_pos) { \
- uint l = strlen(str); \
- for(uint i=0;i<l;i++) { \
- buf[pos+i]=str[i]; \
- } \
- if(affect_pos) { \
- pos += l; \
- }}
- char* join_args(char* strings[], char* seperator, int count) {
- char* str = NULL;
- size_t total_length = 0;
- int i = 0;
- for (i = 0; i < count; i++) total_length += strlen(strings[i]);
- total_length++;
- total_length += strlen(seperator) * (count - 1);
- str = (char*) malloc(total_length);
- str[0] = '\0';
- for (i = 1; i < count; i++) {
- strcat(str, strings[i]);
- if (i < (count - 1)) strcat(str, seperator);
- }
- return str;
- }
- int main(int arg_count, char* args[]) {
- uint buf_size = 2;
- char* arg_s = join_args(args,"",arg_count);
- uint len = strlen(arg_s);
- for(uint i=0;i<len;i++) {
- char c = arg_s[i];
- if(!isdigit(c)) {
- fputs("Usage: kek (numbers)\n", stderr);
- return 1;
- }
- if(c=='1') {
- buf_size+=2;
- } else if(c=='3'||c=='7') {
- buf_size+=3;
- } else {
- buf_size+=4;
- }
- }
- uint pos=0;
- char line_one[buf_size];
- char line_two[buf_size];
- char line_thr[buf_size];
- for(uint i=0;i<buf_size;i++) {
- line_one[i]=' ';
- line_two[i]=' ';
- line_thr[i]=' ';
- }
- for(uint i=0;i<len;i++) {
- char c = arg_s[i];
- if(c=='0') {
- write(line_one, " _ ", pos, false);
- write(line_two, "| | ", pos, false);
- write(line_thr, "|_| ", pos, true);
- } else if(c=='1') {
- write(line_one, " ", pos, false);
- write(line_two, "| ", pos, false);
- write(line_thr, "| ", pos, true);
- } else if(c=='2') {
- write(line_one, " _ ", pos, false);
- write(line_two, " _| ", pos, false);
- write(line_thr, "|_ ", pos, true);
- } else if(c=='3') {
- write(line_one, "_ ", pos, false);
- write(line_two, "_| ", pos, false);
- write(line_thr, "_| ", pos, true);
- } else if(c=='4') {
- write(line_one, " ", pos, false);
- write(line_two, "|_| ", pos, false);
- write(line_thr, " | ", pos, true);
- } else if(c=='5') {
- write(line_one, " _ ", pos, false);
- write(line_two, "|_ ", pos, false);
- write(line_thr, " _| ", pos, true);
- } else if(c=='6') {
- write(line_one, " _ ", pos, false);
- write(line_two, "|_ ", pos, false);
- write(line_thr, "|_| ", pos, true);
- } else if(c=='7') {
- write(line_one, "_ ", pos, false);
- write(line_two, " | ", pos, false);
- write(line_thr, " | ", pos, true);
- } else if(c=='8') {
- write(line_one, " _ ", pos, false);
- write(line_two, "|_| ", pos, false);
- write(line_thr, "|_| ", pos, true);
- } else if(c=='9') {
- write(line_one, " _ ", pos, false);
- write(line_two, "|_| ", pos, false);
- write(line_thr, " _| ", pos, true);
- }
- }
- line_one[buf_size-1] = 0;
- line_two[buf_size-1] = 0;
- line_thr[buf_size-1] = 0;
- puts(line_one);
- puts(line_two);
- puts(line_thr);
- }
- /*
- Anonymous ⋯ EzMake Projects kek bin/kek 42069
- _ _ _ _
- |_| _| | | |_ |_|
- | |_ |_| |_| _|
- Anonymous ⋯ EzMake Projects kek
- */
RAW Paste Data
