Hello,
I am writing a program that reads a file and prints each character of a file in different randomly chosen color. I am using ncurses for that,
But the problem is that i cannot change color per character basis, rather it changes color of full screen each time while refreshing instead of character,
Am i suppose to use something else than chgat, also im not getting black background....Code:#include<ncurses.h> #include<math.h> #include<string.h> #include<stdlib.h> int main(int argc, char *argv[]) { int row, col, x, y, main_Color, r, g, b, c; char ch; FILE *fp; if(argc != 2) { printf("Usage : %s <file>", argv[0]); exit(1); } fp = fopen(argv[1], "r"); if(fp == NULL) { perror("\nCannot open file\n"); exit(1); } initscr(); getmaxyx(stdscr, row, col); start_color(); c = 1; while((ch = fgetc(fp)) != EOF) { getyx(stdscr, y, x); if(y == (row - 1)) { printw("<-- Press any key -->"); getch(); clear(); move(0,0); } main_Color = rand()%8; r = rand()%1001; g = rand()%1001; b = rand()%1001; init_color(main_Color, r,g,b); //c is for random color pair index... init_pair(c, main_Color, COLOR_BLACK); chgat(1, A_NORMAL ,c, NULL); printw("%c", ch); refresh(); c++; } refresh(); getch(); fclose(fp); endwin(); }



LinkBack URL
About LinkBacks



