not able to debug these errors

Started by
4 comments, last by TEUTON 18 years, 1 month ago
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<3)
      return 0 ;
  v1 = pile[0]+pile[1]+pile[plen-1] ;
  
  v2 = pile[0]+pile[plen-2]+pile[plen-1] ;
  
  v3 = pile[plen-3]+pile[plen-2]+pile[plen-1] ;
  
  if (v1==10 || v1==20 || v1==30)
   {  
      card[clen++] = pile[0] ;
      card[clen++] = pile[1] ;
      card[clen++] = pile[plen-1] ;
      for (j=0, plen-=3 ; j<plen ; j++)
         pile[j] = pile[j+2] ;
     pile[plen] = 0 ;
  }
  else if (v2==10 || v2==20 || v2==30)
  {  
     card[clen++] = pile[0] ;
     card[clen++] = pile[plen-2] ;
     card[clen++] = pile[plen-1] ;
     for (j=0, plen-=3 ; j<plen ; j++)
         pile[j] = pile[j+1] ;
     pile[plen] = 0 ;
  }
  else if (v3==10 || v3==20 || v3==30)
  {  
     card[clen++] = pile[plen-3] ;
     card[clen++] = pile[plen-2] ;
     card[clen++] = pile[plen-1] ;
     plen -= 3 ; pile[plen] = 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[j]) ; pile[j]!=0 ;
       i=0, j=0, fscanf(in, "%d", &pile[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]) ;
              plen[j] = 2 ;
          }
      }
      for (i=0, clen=38 ; i<38 ; i++)
          fscanf(in, "%d", &card) ;
      for (i=0 ; !finish ; i++, i%=7)
      {   if (plen==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[plen++] = card[0] ; pile[plen] = 0 ;
             for (j=0, --clen ; j<clen ; j++)
                 card[j] = card[j+1] ;
             card[clen] = 0 ; deal++ ;
             if (plen<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 ;

}
Advertisement
TEUTON

The program compiles fine with Visual Studio 6.0 I didn't get any errors.
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
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
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;
tried but it didn't work...anyways I have mailed them..let's see what they have to say

This topic is closed to new replies.

Advertisement