/* myst_color.c * Written by Myst Shen on Nov. 11, 2008. */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "myst_color.h"
int c, num;
char *rcolor;
NODE * init (FILE *fp){
head = (NODE *)malloc(sizeof(NODE));
head->next = NULL;
tail = head;
while (1){
c = fgetc(fp);
if( c == EOF ) break;
p = (NODE *)malloc(sizeof(NODE));
p->val = c;
p->color = "\33[1;30m";
p->next = NULL;
tail->next = p;
p->prev = tail;
tail = p;
}
return head;
}
char * rand_color (int num) {
int num1, num2;
char *color[] = {
"\33[1;31m",
"\33[1;32m",
"\33[1;33m",
"\33[1;34m",
"\33[1;35m",
"\33[1;36m",
"\33[0;31m",
"\33[0;32m",
"\33[0;33m",
"\33[0;34m",
"\33[0;35m",
"\33[0;36m",
};
srand((unsigned)time(NULL));
num1 = rand()%11 +1;
num2 = num1 - num;
rcolor = color[num2];
return rcolor;
}
int print (NODE *pNODE) {
while(1){
pNODE = pNODE->next;
if ( pNODE == NULL ) break;
printf("%s", pNODE->color);
printf("%c", pNODE->val);
}
putchar ('\n');
return 0;
}
|