Sign in to follow this  
TEUTON

not able to debug these errors

Recommended Posts

I am having errors in this code at line 129 or before it's showing ERROR: missing ')' ERROR: syntax error before or at line 129 in file /home/test.c ==>: for ( ; ptr!=his ; free(ptr->next), ptr->next=0) BUG: for ( ; ptr!=his ; free<== ??? ERROR: missing ';' ERROR: syntax error before or at line 133 in file /home/test.c ==>: for ( ; ptr!=his ; free(ptr->next), ptr->next=0) BUG: for ( ; ptr!=his ; free(ptr->next), ptr->next=0)<== ??? Sorry I don't know how to use code tags..plz help me correct these errors
#include <stdio.h>
#include <stdlib.h>

int i, j, k, deal, finish, clen, card[52], plen[7], pile[7][52] ;

struct History{ 
       int i, clen, card[52], pile[7][52], plen[7] ;
       struct History *next ;
} *his, *ptr ;

int pick(void){ 
    int v1, v2, v3 ;
    if (plen[i]<3)
      return 0 ;
  v1 = pile[i][0]+pile[i][1]+pile[i][plen[i]-1] ;
  
  v2 = pile[i][0]+pile[i][plen[i]-2]+pile[i][plen[i]-1] ;
  
  v3 = pile[i][plen[i]-3]+pile[i][plen[i]-2]+pile[i][plen[i]-1] ;
  
  if (v1==10 || v1==20 || v1==30)
   {  
      card[clen++] = pile[i][0] ;
      card[clen++] = pile[i][1] ;
      card[clen++] = pile[i][plen[i]-1] ;
      for (j=0, plen[i]-=3 ; j<plen[i] ; j++)
         pile[i][j] = pile[i][j+2] ;
     pile[i][plen[i]] = 0 ;
  }
  else if (v2==10 || v2==20 || v2==30)
  {  
     card[clen++] = pile[i][0] ;
     card[clen++] = pile[i][plen[i]-2] ;
     card[clen++] = pile[i][plen[i]-1] ;
     for (j=0, plen[i]-=3 ; j<plen[i] ; j++)
         pile[i][j] = pile[i][j+1] ;
     pile[i][plen[i]] = 0 ;
  }
  else if (v3==10 || v3==20 || v3==30)
  {  
     card[clen++] = pile[i][plen[i]-3] ;
     card[clen++] = pile[i][plen[i]-2] ;
     card[clen++] = pile[i][plen[i]-1] ;
     plen[i] -= 3 ; pile[i][plen[i]] = 0 ;
  }
  else
     return 0 ;
  return 1 ;
}

int main(void)
{ 
    FILE *in ;

  in = fopen("10-20-30.in", "r") ;

  for (i=0, j=0, fscanf(in, "%d", &pile[i][j]) ; pile[i][j]!=0 ;
       i=0, j=0, fscanf(in, "%d", &pile[i][j]))
  {   deal = 14 ; finish=0 ; ptr = his = 0 ;
      for (i=0, j=1 ; i<2 ; i++, j=0)
      {   for ( ; j<7 ; j++)
          {   fscanf(in, "%d", &pile[j][i]) ;
              plen[j] = 2 ;
          }
      }
      for (i=0, clen=38 ; i<38 ; i++)
          fscanf(in, "%d", &card[i]) ;
      for (i=0 ; !finish ; i++, i%=7)
      {   if (plen[i]==0)
          {  if (plen[0]==0 && plen[1]==0 && plen[2]==0 && plen[3]==0 &&
                 plen[4]==0 && plen[5]==0 && plen[6]==0)
                finish = 1 ;
          }
          else
          {  if (clen==0)
             {  finish = 2 ;
                continue ;
             }
             pile[i][plen[i]++] = card[0] ; pile[i][plen[i]] = 0 ;
             for (j=0, --clen ; j<clen ; j++)
                 card[j] = card[j+1] ;
             card[clen] = 0 ; deal++ ;
             if (plen[i]<3) continue ;
             while (pick()) ;
          }
          if (his!=0 && !finish)
             for (ptr=his ; ptr!=0 && !finish ; ptr=ptr->next)
             {   if (i!=ptr->i || clen!=ptr->clen) continue ;
                 for (j=0 ; j<7 ; j++)
                     if (plen[j]!=ptr->plen[j])
                        break ;
                 if (j!=7) continue ;
                 for (j=0 ; j<clen ; j++)
                     if (card[j]!=ptr->card[j])
                        break ;
                 if (j!=clen) continue ;
                 for (j=0 ; j<7 ; j++)
                     for (k=0 ; k<plen[j] ; k++)
                         if (pile[j][k]!=ptr->pile[j][k])
                            break ;
                 if (j==7) finish = 3 ;
             }
          if (!finish)
          {  if (his!=0)
             {  for (ptr=his ; ptr->next!=0 ; ptr=ptr->next) ;
                ptr->next = (struct History *) malloc(sizeof(struct History)) ;
                ptr->next->next = 0 ;
             }
             else
             {  his = ptr = (struct History *) malloc(sizeof(struct History)) ;
                ptr->next = 0 ;
             }
             ptr->i = i ; ptr->clen = clen ;
             for (j=0 ; j<7 ; j++)
                 ptr->plen[j] = plen[j] ;
             for (j=0 ; j<clen ; j++)
                 ptr->card[j] = card[j] ;
             for (j=0 ; j<7 ; j++)
                 for (k=0 ; k<plen[j] ; k++)
                     ptr->pile[j][k] = pile[j][k] ;
          }
      }
      if (finish==1)
         printf("Win : %d\n", deal) ;
      else if (finish==2)
         printf("Loss: %d\n", deal) ;
      else if (finish==3)
         printf("Draw: %d\n", deal) ;
      for ( ; ptr!=his ; free(ptr->next), ptr->next=0)
          for (ptr=his ; ptr->next->next!=0 ; ptr=ptr->next) ;
      free(ptr) ;
  }
  fclose(in) ;
  system("pause");
  return 0 ;

}

Share this post


Link to post
Share on other sites
Ditto for Borland 5.6.4, GCC 3.3.1, Visual C++ 7.1 and Visual C++ 8.0, although I didn't bother looking through your code. What compiler are you using?

You can use [source] tags to display code in a scrollable formatted box.

Σnigma

Share this post


Link to post
Share on other sites
Yaa even i tried that with gcc and VC6.0..actually I am participating in an online contest(which i will not tell you :))...they have their online compiler and its showing these errors...don't know what to do about them..
I'll rather mail that to them

Share this post


Link to post
Share on other sites
Perhaps their compiler doesn't like the for (; syntax, with the empty statement.

You could try putting a statement with no side effects in and see if it compiles ok , e.g. for ( 0;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this