By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,657 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,657 IT Pros & Developers. It's quick & easy.

debug prob..

P: 5
im not able to figure out the error.. can someone help me with this..
the code is..
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. #define MAX_STATES    20
  6. #define MAX_VARS    5
  7. #define MAX_TRANS    10         
  8. #define MAX_LEN        20
  9.  
  10. struct  TransTbl
  11. {
  12.     char trans[MAX_TRANS];
  13.     int nt;    
  14. };
  15.  
  16. struct TransTbl tt[MAX_STATES][MAX_VARS];
  17. char vars[MAX_VARS];
  18. char re[MAX_LEN];
  19. int NS = 0;        //keeps count of states..
  20. int nv;            //no of vars..
  21.  
  22. /*initialize nt for the objects..*/
  23. int i,j;
  24. for(i=0; i<MAX_STATES; i++)
  25.     for(j=0; j<MAX_VARS; j++)
  26.         tt[i][j].nt = 0;
  27.  
  28.  
the error : syntax error befor for
Mar 18 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 1,510
for() is an executable statement so can only occur in a function, e.g. in main()
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. for(i=0; i<MAX_STATES; i++)
  4.     for(j=0; j<MAX_VARS; j++)
  5.         tt[i][j].nt = 0;
  6.  
  7.  
Mar 18 '07 #2

P: 5
hey thanks a lot!
it worked!
Mar 18 '07 #3

P: 5
now another problem..
im pretty sure im allowed to do this but i may be wrong..
the code..

printf("Enter no of vars : ");
scanf("%d", &nv);

printf("Enter vars..");
for(i=0; i<nv; i++)
scanf("%c", vars[i]);
vars[i] = 'E';

when i give input for "vars" it crashes.. and the "nv" i gave was 2.
btw the declaration(global) of vars is char vars[MAX_VARS] where max vars is 5

what am i doing wrong..
Mar 18 '07 #4

arne
Expert 100+
P: 315
now another problem..
im pretty sure im allowed to do this but i may be wrong..
the code..

printf("Enter no of vars : ");
scanf("%d", &nv);

printf("Enter vars..");
for(i=0; i<nv; i++)
scanf("%c", vars[i]);
vars[i] = 'E';

when i give input for "vars" it crashes.. and the "nv" i gave was 2.
btw the declaration(global) of vars is char vars[MAX_VARS] where max vars is 5

what am i doing wrong..

Try '&vars[i]' instead of 'vars[i]' in the scanf.
Mar 18 '07 #5

P: 5
thanks a lot! it works
i also had to change the "%c" to "%s"
Mar 18 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.