Search code examples
cbgi

Declaration error in my code


I am getting an error on Line 48 in the following code:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>

void swap(int a,int b);void bar1();void bar2();
void bar3();  void bar4();  check0(); check1();
check2(); void del(); void rod1(); void rod2();
void box1();void box2();void tee1();voidtee2();
void tee3();void tee4();check3();void insert();
void again();void print();void myremove();void frame();
int score=0,spd,q,t,a=0,i,j,l[6]={300,90,315,105,301,91},p,turn,m,n;
char play='y';
static int arr[26][13];
void main(void)
{

   char ch,y;
   int gd= DETECT,gm,area,maxx,maxy,move,lmove,rmove;
   void *buff;
   initgraph(&gd,&gm,"d:\tc\bgi");
do{

   turn=1;
    score=0;
   do{
   clrscr();
   cleardevice();
   printf(" Enter Your Choice");
   printf(" Basic Level.......... 1");
   printf(" Middle Level......... 2");
   printf(" Advanced Level....... 3");
   printf(" Experts Level........ 4");
   printf(" Professional Level... 5");
   y=getch();
   clrscr();
   cleardevice();
   if(y=='1') {spd=200; settextstyle(2,0,6);outtextxy(2,150,"   BasicLevel ");break;}
   if(y=='2') {spd=150; settextstyle(2,0,6);outtextxy(2,150,"   MiddleLevel ");break;}
   if(y=='3') {spd=100; settextstyle(2,0,6);outtextxy(2,150,"  AdvancedLevel ");break;}
   if(y=='4') {spd=75; settextstyle(2,0,6);outtextxy(2,150,"  ExpertsLevel ");break;}
   if(y=='5') {spd=50;  settextstyle(2,0,6);outtextxy(2,150,"ProfessionalLevel ");break;}
      }while(1);

   frame();
   getch();
int k,ar[2],pr[2],t[6];

randomize();
ar[0]=random(2);
pr[0]=random(6);
ar[1]=random(2);
pr[1]=random(6);
while(1)
{
printf(" score= %d",score);
a=ar[0];
p=pr[0];
l[0]=450;l[1]=250;l[2]=465;l[3]=265;l[4]=451;l[5]=251;

if(y=='1') spd=100;
if(y=='2') spd=75;
if(y=='3') spd=50;
if(y=='4') spd=30;
if(y=='5') spd=20;
print();

delay(500);
a=ar[1];
p=pr[1];

t[0]=l[0];  t[1]=l[1]; t[2]=l[2];
t[3]=l[3];  t[4]=l[4]; t[5]=l[5];

a=ar[1];
p=pr[1];

l[0]=270;l[1]=90;l[2]=285;l[3]=105;l[4]=271;l[5]=91;

It looks like there's something wrong after getch(). The entire source code is over here: http://codepad.org/I1cQQxJE

Thank you for any hints you can provide to help resolve the error


Solution

  • Line 48 is:

    int k,ar[2],pr[2],t[6];
    

    so I suspect you're using a pre-C99 compiler (as evidenced by the archaic use of conio.h, a favorite of some universities who continue to use the 20-year-old, outdated, Borland C despite the availability of more modern and equally cheap options like gcc).

    If so, you need to declare variables at the top of a block.