Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What do you code in your free time?

Name: Anonymous 2009-03-20 15:41

I mean, everything has been already done by someone else and I don't think everyone is involved in BIG projects and shit like that.

Name: Anonymous 2009-03-20 19:46

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char *bbcode[10] = {
    "o", "spoiler", "aa", "m",
    "sub", "sup", "s", "b", "u", "i"
};

typedef struct stack_t {
    int value;
    struct stack_t *next;
} stack_t;

stack_t *push(int value, stack_t *stack) {
    stack_t *buf;

    if ((buf = malloc(sizeof(stack_t))) == NULL)
        return NULL;

    buf->value = value;
    buf->next = stack;
  
    return buf;
}

stack_t *pop(int *out, stack_t *stack) {
    stack_t *next = NULL;

    if(stack != NULL) {
        *out = stack->value;
        next = stack->next;
        free(stack);
    }
  
    return next;
}

int main(int argc, char **argv) {
    stack_t *stack = NULL;
    int maxcode, arg, pushorpop, code;
    int pushed = 0;

    srand(time(NULL));
    maxcode = sizeof(bbcode)/sizeof(char*);

    if(argc == 1) {
        return -1;
    }

    for(arg = 1; arg < argc; arg++) {
        pushorpop = rand() % 2;
        if(pushed == 0)
            pushorpop = 0;

        if(pushed > 4)
            pushorpop = 1;

        if(pushorpop == 0) {
            code = rand() % maxcode;
            stack = push(code, stack);
            pushed++;
            printf(" [%s]", bbcode[code]);
        } else {
            stack = pop(&code, stack);
            pushed--;
            printf("[/%s] ", bbcode[code]);
        }
        printf("%s", argv[arg]);
    }
    while(pushed > 0) {
        stack = pop(&code, stack);
        pushed--;
        printf("[/%s]", bbcode[code]);
    }
    printf("\n");
    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List