Search code examples
ccompiler-errorscodeblocksturbo-c++bgi

"Type mismatch in parameter" when using setfillpattern()?


I have started working on a C project to build a PacMan game, but I am getting an error when I execute below code. The error is generated by Code::Blocks as well as Turbo C++ 3.5. In Code::Blocks I remove the path which is "C:\TurboC3\BGI",but the error still continues.

Error in Turbo C++ Turbo C++ error

Error in Code::Blocks Error in Code::Blocks

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
    int gd=0,gm;
    initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
    setfillpattern(SOLID_FILL,YELLOW);
    circle(200,100,10);
    line(200,250,200,250);
    line(225,250,225,250);
    line(250,250,250,250);
    line(275,250,275,250);
    line(300,250,300,250);
    line(325,250,325,250);
    arc(50,225,110,-100,30);
    printf("Hello...Let's Play PacMan !! \n\n");
    getch();
    closegraph();
    return 0;
}

Solution

  • I don't use BGI, but a quick search finds that setfillpattern is expecting a char array as the first parameter, but SOLID_FILL is of type enum fill_styles. To use SOLID_FILL you need to call setfillstyle instead.

    To use setfillpattern you need to supply a custom pattern:

    char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00};
    setfillpattern(pattern, YELLOW);