Please read this code and fix the bug.HELP needed URGENTLY!!

Discussion in 'C' started by jose_peeterson, Jun 15, 2011.

  1. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    hi i tried making the mineweeper game for my project.it does not seem to work. i dont know the bug inside.please some one read it and fix it for me please

    sorry its quite big please help.
    please try compile and then debug. the problem is with the rand_mines() function i think, and i cannot print the 2d array because i get this warning.pointer to integer without cast, please help me in need it fast. i am a newbie....

    Code:
    #include<stdio.h>  // interger to pointer without cast PROBLEM....
    #include<stdlib.h>
    
    void welcome();
    void rand_mines(int msweep[12][12]);
    void printmatrix(int a[11][11],int r);
    int process(int msweep[12][12],int r,int c);
    
    int main()
    
    {
    
    int msweep[12][12] = {{0}};      
    int i,r,c;   
    
     welcome();   
        
     rand_mines(msweep);  
    
    // printmatrix(msweep,11);  // note grid from 1 to 11  
      
      printf("Enter you location on the minefield x,y\n");
      scanf("%d%d",&r,&c);
    
      i = process(msweep,r,c);
      
         
      while(i)     
       {
         printf("Lucky BRAT, live on for another step\n");      
         printf("enter next move ... ");
         scanf("%d%d",&r,&c);
       
         
         i = process(msweep,r,c);    
       
       printf(" %d Surrounding MINEs\n",msweep[r][c]);
        
       }  
    
      if(i=0)
       printf("Game OVER, ta ta. you stepped on a MINE !!\n");
    
    return 0;    
        
    }
    
    void welcome()
    {
    
    char op;
    
     printf("Welcome to MINESWEEPER in C >>.....\n");
    
     printf("Enter <<\n");
     printf("         i for instructions\n");
     printf("         e to enter game\n");
     scanf("%c",&op);
    
     if(op == 'i')
      {
       printf("OH DEAR, what a shock you are unfortunatly in the midst of a "); printf("mine field.\n");    
       printf("Enter the coordinates of the x and y plane between 0 to 9\n");   
       printf("Are you destined to DIE or live ?\n");
       printf("HA ha ha huh, GOOD LUCK\n");
      
      }
    else
     return;    
    }
    
    void rand_mines(int msweep[12][12])
    
    {
        
    int r,c,m;
    
     //srand(12);   
     
     for(m=0;m<20;m++)
      {
       r = rand() % 11;    
        if(r = 0)  
          r = 10;
    
       c = rand() % 11; 
        if(c == 0)
          c = 2;
       
       msweep[r][c] = 9; 
      printf("%d %d \n",r,c);
      }  
        
    return;
    
    }
    
    void printmatrix(int a[][11],int r)
    {
        
    int i,j;    
     
     for(i=1;i<r;i++)
      {
       for(j=1;j<11;j++)    
        {
         printf("%d ",a[i][j]);     
        } 
       printf("\n");   
      
      }
    
    return;    
    }
    
    int process(int msweep[12][12],int r,int c)
    {
        
     int i,j,b=0;    
        
     if(msweep[r][c] == 9)   
       return 0; 
     else
      {
       if(msweep[i-1][j-1] == 9)    
        b++;  
       if(msweep[i-1][j] == 9)    
        b++;  
       if(msweep[i-1][j+1] == 9)    
        b++;  
       if(msweep[i][j-1] == 9)    
        b++;  
       if(msweep[i][j+1] == 9)    
        b++;  
       if(msweep[i+1][j-1] == 9)    
        b++;  
       if(msweep[i+1][j] == 9)    
        b++;  
       if(msweep[i+1][j+1] == 9)    
        b++;  
      
       msweep[r][c] = b;
      }
        
     return 1;  
        
    }
     
    Last edited by a moderator: Jun 16, 2011
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Could you explain how your process() function is meant to work?
     
  3. jose_peeterson

    jose_peeterson New Member

    Joined:
    May 19, 2011
    Messages:
    56
    Likes Received:
    1
    Trophy Points:
    0
    Thanks mr xpi0t0s, for seeing my code
    i have finished the game already.
    please take a look and give me some comments
    the source code is a bit messy but i put in lot of comments
    you can view this game under thread name simple minesweeper game in c.
    take care
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice