/* myst_color.c
* written by Myst Shen on Sep. 16, 2008.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "myst_color.h"
int ch, c, num;
char *rcolor;
FILE *fp;
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->next = NULL;
tail->next = p;
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[1;37m",
"\33[0;31m",
"\33[0;32m",
"\33[0;33m",
"\33[0;34m",
"\33[0;35m",
"\33[0;36m",
"\33[0;37m"
};
srand((unsigned)time(NULL));
num1 = rand()%13 +1;
num2 = num1 - num;
rcolor = color[num2];
return rcolor;
}
int print (NODE *p) {
while(1){
p = p->next;
if ( p == NULL ) break;
printf("%s", p->color);
printf("%c", p->val);
}
putchar ('\n');
return 0;
}
|