c - how to create a union -
i made mistake while using union,and don't know why. problem in function goto_xy();
read book, cannot compiled. in function trying locate cursor, regs
variable not declared. want know function.
#include<stdio.h> #include<windows.h> #include<dos.h> #include<conio.h> void goto_xy(int x,int y); //goto key word;define subfunction creat original cursor int coordinate system void rectangle_clear(int x1,int x2,int y1,int y2); //define rectangle_clear opening subfunction void center_clear(int x1,int x2,int y1,int y2); //define center_clear opening subfunction void creat(); //define subfunction of creating star int main() //the main function { creat(); getch(); center_clear(0,25,0,79); getch(); } void center_clear(int x1,int x2,int y1,int y2) //the subfunction creats stars while opening project { int x00,y00,x0,y0,i,d; if((y2-y1)>(x2-x1)) { d=(x2-x1)/2; x0=(x1+x2)/2; y0=y1+d; y00=y2-d; for(i=0;i<(d+1);i++) { rectangle_clear((x0-i),(x00+i),(y0-i),(y00+i)); } delay(10); //to delay dismis of star } else { d=(y2-y1)/2; y0=(y1+y2)/2; x0=x1+d; x00=x2-d; for(i=0;i<d+1;i++) { rectangle_clear((x0-i),(x00+i),(y0-i),(y00+i)); } delay(10); } } void rectangle_clear(int x1,int x2,int y1,int y2) //to creat star int shape of rectangle { int i,j; for(i=y1;i<y2;i++) { goto_xy(x1,i); putchar(' '); goto_xy(x2,i); putchar(' '); delay(10); } for(j=x1;j<x2;j++) { goto_xy(i,y1); putchar(' '); goto_xy(i,y2); putchar(' '); delay(10); } } void goto_xy(int x,int y) { union regs r; r.h.ah=2; r.h.dl=y; r.h.dh=x; r.h.bh=0; int86(0x10,&r,&r); } void creat() { int i,j; for(i=0;i<24;i++) { for(j=0;j<79;j++) { goto_xy(i,j); printf("a"); } } }
it appears me union regs
must present in 1 of header files , including same.
as can seen code below, members of union h
, members of h
present, means union there in header file , including it.
void goto_xy(int x,int y) { union regs r; r.h.ah=2; //here accessing member of regs , sub-members of h r.h.dl=y; r.h.dh=x; r.h.bh=0; int86(0x10,&r,&r); }
edit: google search tells me union regs
defined in dos.h
, like
union regs { struct wordregs x; struct byteregs h; };
so, need include dos.h solve problem. but, appears inspite of including that, problem present. can open dos.h , check if union regs present or not.
see here more details.
Comments
Post a Comment