Thread: can't compile

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    40

    can't compile

    I am using Metrowerks Code Warrior, I had somebody helping me with this. It compiles on his compiler (not the same as mine) but I am getting like 99 errors! Can't open dos.h, and can't open graphics.h and so on.
    Can somebody look at this and see if anything jumps out at you?
    Thanks!!

    Code:
     
    //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    //=This program is for the game "Tic Tac Toe".                               -
    //-here the two players plays the game using the navigation key              =
    //=i.e. the arrow keys "up, down, right, left" to navigate through the panel -
    //-and selects a particular box by pressing the enter key.                   =
    //=                                                                          -
    //-if a particular user wins the game the program waits for key to be pressed=
    //=and after the key is press it returns back to the main function           -
    //-if at all if a user wants to exit then he need to press the Esc key       =
    //=to get out of the program.                                                -
    //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    
    
    // this program runs perfectly on turbo c++ compiler version 3
    //provided graphic library is enabled and the bgi folder is at the location
    //c:\tc\bgi
    
    
    
    #include <graphics.h>
    #include <stdlib.h>
    #include <dos.h>
    #include <stdio.h>
    #include <conio.h>
    void operation(int left,int top); //u need to just implement this in class of
    //c++ if ur intrested in making c++ class for this
    int check(int a[3][3]);
    void main(void)
    {
       int gdriver = DETECT, gmode, errorcode;
       int left,top ,i,j,x,y;
    
       initgraph(&gdriver, &gmode, "C:\Program Files\Metrowerks\CodeWarrior\Win32-x86 Support\Libraries\Win32 SDK");     //here u need to specify the location of bgi folder for drivers help
    						   // if u dont specify this ur program will not work
       errorcode = graphresult();
       if (errorcode != grOk)  /* an error
           occurred */
       {
          printf("Graphics error: %s\n", grapherrormsg(errorcode));
          printf("Press any key to halt:");
          getch();
          exit(1); /* terminate with an error
    		  code */
       }
    
      left=x = 160;
      top=y = 89     ;
          setfillstyle(1,12);
          for( i=0;i<3;i++)
          {
          for( j=0;j<3;j++)
          {
          bar(left,top,left+100, top+100);
          left=left+106;
          }
          top=top+106;
          left=x;
          }
          top=y;
          setcolor(12);
          rectangle(left-3,top-3,left+315,top+315);
          rectangle(left-5,top-5,left+317,top+317);
          line(left+103,top-3,left+103,top+315);
          line(left+209,top-3,left+209,top+315);
          line(left-3,top+103,left+315,top+103);
          line(left-3,top+209,left+315,top+209);
          setcolor(15);
          settextstyle(3,0,4);
          outtextxy(205,10,"\"TIC TAC TOE\"");
          setcolor(15);
          settextstyle(3,0,2);
          outtextxy(515,155,"PLAYER2:");
          setcolor(14);
          outtextxy(20,155,"PLAYER1:");
          setcolor(8);
          settextstyle(0,0,4);
          outtextxy(45,190,"O");
          outtextxy(545,190,"X");
          operation(left,top);
        getch();
       /* clean up */
       closegraph();
    }
    
    
    void rect(int left,int top)
    {
    rectangle(left-1,top-1,left+101,top+101);
    }
    
    void operation(int left,int top)
    {
    int i,j,p=0,x=left;
    int a[3][3],y=top,key,r=0,c=0;
    setcolor(14);
    rect(left,top);
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    a[i][j]=-1;
    while(1)
    {
    key=getch();
    if (key==13)
    {   setcolor(0);
    settextstyle(0,0,6);
       if(p==1&&(a[r][c]!=0&&a[r][c]!=1))
       {
       outtextxy(left+25,top+25,"X");
       p=a[r][c]=0;
       setcolor(14);
       settextstyle(3,0,2);
       outtextxy(20,155,"PLAYER1:");
       setcolor(15);
       outtextxy(515,155,"PLAYER2:");
    
    
       }
       else if(p==0&&(a[r][c]!=0&&a[r][c]!=1))
       {
       outtextxy(left+25,top+25,"O");
       p=a[r][c]=1;
       setcolor(15);
       settextstyle(3,0,2);
       outtextxy(20,155,"PLAYER1:");
       setcolor(14);
       outtextxy(515,155,"PLAYER2:");
    
    
       }
       else
    	{
    	setcolor(15);
    	settextstyle(0,0,2);
    	outtextxy(255,420,"Sorry...");
    	delay(500);
    	setfillstyle(1,0);
    	bar(255,420,375,435);
    	}
       }
    else if(key==27)
    exit(0);
    else if(key==72)
    {
    if(top==y)
    top=y;
    else{
    setcolor(0);
    rect(left,top);
    top=top-106;
    r=r-1;
    setcolor(14);
    rect(left,top);}
    }
    
    else if(key==80)
    {
    if(top==301)
    top=301;
    else{
    setcolor(0);
    rect(left,top);
    top=top+106;
    r=r+1;
    setcolor(14);
    
    rect(left,top);}
    }
    
    else if(key==77)
    {
    if(left==372)
    left=372;
    else{
    setcolor(0);
    rect(left,top);
    left=left+106;
    c=c+1;
    setcolor(14);
    rect(left,top);}
    }
    
    else if(key==75)
    {
    if(left==x)
    left=x;
    else{setcolor(0);
    rect(left,top);
    left=left-106;
    c=c-1;
    setcolor(14);
    rect(left,top);}
    }
    key=check(a);
    if(key!=0)
    {
    getch();  // waits for one keystroke
    main();   /// for returning back to main function after somebody wins
    }
    }
    }
    
    
    int check (int a[3][3])    /// these function cheks whether any one plyers has win the game or not
    {
    int i,j,count=0;
    for (i=0;i<3;i++)
    {
    for (j=0;j<3;j++)
     {
     if(a[i][j]==1)
       count=count+1;
     }
     if (count==3)
      {
      setfillstyle(1,0);
      bar(45,190,75,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(20,190,"WINS !");
      return (1);
      } count=0;
    
    for (j=0;j<3;j++)
     {
     if(a[i][j]==0)
       count=count+1;
     }
     if (count==3)
    {
      setfillstyle(1,0);
      bar(545,190,575,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(510,190,"WINS! ");
       return (1);
    
    }
     count=0;
    }
    for (j=0;j<3;j++)
    {
    for (i=0;i<3;i++)
     {
     if(a[i][j]==1)
       count=count+1;
     }
     if (count==3)
     {setfillstyle(1,0);
      bar(45,190,75,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(20,190,"WINS !");
      return(1);
      }
     count=0;
    
    for (i=0;i<3;i++)
     {
     if(a[i][j]==0)
       count=count+1;
     }
     if (count==3)
    {
      setfillstyle(1,0);
      bar(545,190,575,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(510,190,"WINS! ");
      return(1);
    }
     count=0;
    }
    for(i=0;i<3;i++)
    {
     if(a[i][i]==1)
       count=count+1;
    
     if (count==3)
      {
      setfillstyle(1,0);
      bar(45,190,75,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(20,190,"WINS !");
      return(1);
      }
    
    }
    count=0;
    for(i=0;i<3;i++)
    {
     if(a[i][i]==0)
       count=count+1;
    
      if (count==3)
    {
      setfillstyle(1,0);
      bar(545,190,575,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(510,190,"WINS! ");
      return(1);
    }
    }
       count=0;
    for(i=0,j=2;i<3,j>=0;i++,j--)
    {
     if(a[i][j]==1)
       count=count+1;
    
     if (count==3)
      {
      setfillstyle(1,0);
      bar(45,190,75,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(20,190,"WINS !");
     return(1);
      }
    }
    count=0;
    for(i=0,j=2;i<3,j>=0;i++,j--)
    {
     if(a[i][j]==0)
       count=count+1;
    
      if (count==3)
    {
      setfillstyle(1,0);
      bar(545,190,575,220);
      setcolor(14);
      settextstyle(8,0,4);
      outtextxy(510,190,"WINS! ");
      return(1);
    }
    }
       count=0;
    return 0;
    }

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Its cause your using a newer compiler. Find an old compiler that supports dos
    Woop?

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    I would rather change the program to work with my compiler, is this possible?
    Of course I would need help!

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    What compiler was it that it worked on?

    At any rate, dos.h, conio.h, and graphics.h are not standard headers, and are therefore, probably not included with your compiler.

    As a side note, 'void main' is not technically valid. It should be 'int main'. That should not be causing compile-time errors.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    That should not be causing compile-time errors.
    Any good compiler will cause compile time errors if you are using void main().

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    True... But I have yet to see one that does.

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    Quote Originally Posted by Zach L.
    At any rate, dos.h, conio.h, and graphics.h are not standard headers, and are therefore, probably not included with your compiler.
    What can I replace these with?

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Actually I should have said error or warning. I have it setup so that warnings are treated as errors

  9. #9
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Well, conio.h is probably just used for the getch( ) at the end of main( ). You can just put a cin.get( ) there to have (roughly) the same effect (puasing at the end).

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I am using Metrowerks Code Warrior,
    Okay, you shouldn't expect a Borland library to work with CodeWarrior... If you want to compile this code, get Turbo C++ and an operating system old enough to run it.

    >Can somebody look at this and see if anything jumps out at you?
    Two things jump out at me (aside from the yucky formatting), and I get the impression that this isn't C++.

    >void main(void)
    No cookie for you! The void is dangerous; it forces itself on unsuspecting programs and causes a plague of erratic behavior. The void must be stopped! It is 3VIL!

    >main();
    This is a bad thing even in a language that allows it, such as C. It's only use is for the IOCCC.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 02:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 01:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM