Subj : read foregrnd / backgrnd colors To : borland.public.cpp.borlandcpp From : "Rob C." Date : Tue Aug 26 2003 03:51 pm OK. So now I have it so the function returns the proper data, split up in a character array. Yes it works this way, but as you can see it is very clumsy, inelegant code. (And I get some not- so-good warning messages). There must be a better way! For my program below it returns 7420, which is exactly right, 7 for white background, 4 for red foreground, and 20 (decimal 32) for whitespace character. When I run the program with different foreground and background colors, again it is absolutely correct. What I need is to be able to tear the number apart, so I have ‘7,’ ‘4,’ and ‘20.’ The value returned is a hexadecimal number, however, and that causes problems for me. If it was decimal, for example, I could easily convert it to a character array and work with the subscripts. #include #include #include #include #include char *readattr(); //<- it says, no protype, but this is it, right? int readch();//<- it says, no protype, but this is it, right? void window(int left, int top, int right, int bottom); void textbackground(int newcolor); void clrscr(void); void gotoxy(int x, int y); int readch() { struct REGPACK rp = {0}; rp.r_ax = 0x0800; intr(0x10, &rp); return rp.r_ax & 0x00ff ; } char *readattr() { FILE *fp; struct REGPACK rp = {0}; char attr[100]; rp.r_ax = 0x0800; intr(0x10, &rp); fp = fopen("convert.txt", "wt"); if (fp == NULL) { printf("saveattr 42 error open convert.txt for write.\n"); getch(); return 1; } fprintf( fp, "%x", rp.r_ax ); fclose(fp); fp = fopen("convert.txt", "rt"); if (fp == NULL) { printf("saveattr 57 error open convert.txt for read.\n"); getch(); return 1; } fscanf( fp, "%s", attr ); fclose(fp); return attr; //rp.r_ax; //0x00ff ; } int main() { int FG, BG, i, xcol, xrow, col=30, row=10; int SAVECOL, SAVEROW; char results[10], ch[5]; FG= 4; BG= 7; textcolor(FG); textbackground(BG); gotoxy( col, row-1 ); cprintf( " \n" ); gotoxy( col, row ); cprintf( " adfyghsfghdvgedhjghjrh \n" ); gotoxy( col, row+1 ); cprintf( " adfyghsfghdvgedhjghjrh \r\n" ); gotoxy( col, row+2 ); cprintf( " adfyghsfghdvgedhjghjrh \n" ); gotoxy( col, row+3 ); cprintf( " \n" ); xcol=5; xrow=1; SAVECOL = col; SAVEROW = row; while(1) { //94 gotoxy( col, row ); strcpy( results, readattr() ); // col, row ) ); i = readch(); sprintf( ch, "%d", i ); gotoxy( xcol, xrow ); cprintf( " Background = '%c' \n", results[0] ); gotoxy( xcol, xrow+1 ); cprintf( " Foreground = '%c' \n", results[1] ); gotoxy( xcol, xrow+2 ); cprintf( " character = '%s'\n", ch ); textcolor(3); gotoxy( col, row ); cprintf( "%c\r\n", i ); getch(); textcolor(FG); gotoxy( col, row ); cprintf( "%c\r\n", i ); col++; if( i == '\0' ) { col = SAVECOL; row++; } } //94 return; } .