-2

ユニオンの使用中に間違いを犯しましたが、その理由がわかりません。goto_xy(); 問題は本から読んだ関数にありますが、コンパイルできません。この関数では、カーソルを見つけようとしていますが、REGS変数が宣言されていません。その機能は何か知りたいです。

#include<stdio.h>
#include<windows.h>
#include<dos.h>
#include<conio.h>

void goto_xy(int x,int y);                         //goto is a key word;define the subfunction to creat the original cursor int the coordinate system
void rectangle_clear(int x1,int x2,int y1,int y2); //define the rectangle_clear opening subfunction 
void center_clear(int x1,int x2,int y1,int y2);    //define the center_clear opening subfunction
void creat();                                  //define the subfunction of creating the 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 which creats the stars while opening the 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 the dismis of the 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 the star int the shape of a 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");
        }
    }
}
4

2 に答える 2

1

ほとんどの場合、ユニオンREGSはヘッダーファイルの1つにすでに存在している必要があり、同じものをインクルードしているように見えます。

以下のコードからわかるように、のようなユニオンのhメンバーとのメンバーhも存在します。これは、ユニオンがいくつかのヘッダーファイルにあり、それをインクルードしていることを意味します。

void goto_xy(int x,int y)
{
    union REGS r;

    r.h.ah=2; //Here you are accessing the member of REGS and even the sub-members of h
    r.h.dl=y;
    r.h.dh=x;
    r.h.bh=0;
    int86(0x10,&r,&r);
}

編集: グーグル検索はそれUNION REGSがで定義されることを教えてくれますdos.hそしてそれはいくつかのようなものです

union REGS { 
 struct WORDREGS x;
 struct BYTEREGS h;
};

したがって、問題を解決するにはdos.hを含める必要があります。しかし、それを含めても、この問題は存在しているように見えます。dos.hを開いて、ユニオンREGSが存在するかどうかを確認することもできます。

詳細については、こちらをご覧ください。

于 2013-03-04T14:36:12.973 に答える
0

を定義するunionには、次の手順を実行する必要があります。

union REGS { some_type h; other_type f; };

これで、タイプの変数を作成しREGS、共用体を使用できるようになりました。

于 2013-03-04T14:32:20.723 に答える