Closed Thread
Results 1 to 4 of 4

Thread: need urgent help finding parce error!!!

  1. #1
    siren is offline Newbie
    Join Date
    Apr 2007
    Posts
    10
    Rep Power
    0

    Exclamation need urgent help finding parce error!!!

    Sorry for the minor problem but I need help!! I need to hand in this program in a few hours but I can't seem to find the parce error!!!

    Code:
    #include<stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    main()
    {   
      int a;
      int num[3][3];
      srand((unsigned)time(NULL));
      a = rand() % (7 + 1);      /* getting random numbers 0-7*/
     
      switch(a){
      case 0:     /* if a=0 and so on*/
        num[3][3]={{8, 1, 6}, {3, 5, 7}, {4, 9, 2}};
        printf("%d", num[3][3]);
        break;
      case 1:
        num[3][3]={{4, 3, 8}, {9, 5, 1}, {2, 7, 6}};
        printf("%d", num[3][3]);
        break; 
      case 2:
        num[3][3]={{2, 9, 4}, {7, 5, 3}, {6, 1, 8}};
        printf("%d", num[3][3]);
        break; 
      case 3:
        num[3][3]={{6, 7, 2}, {1, 5, 9}, {8, 3, 4}};
        printf("%d", num[3][3]);
        break; 
      case 4:
        num[3][3]={{6, 1, 8}, {7, 5, 3}, {2, 9, 4}};
        printf("%d", num[3][3]);
        break;
      case 5:
        num[3][3]={{8, 3, 4}, {1, 5, 9}, {6, 7, 2}};
        printf("%d", num[3][3]);
        break; 
      case 6:
        num[3][3]={{4, 9, 2}, {3, 5, 7}, {8, 1, 6}};
        printf("%d", num[3][3]);
        break; 
      case 7:
        num[3][3]={{2, 7, 6}, {9, 5, 1}, {4, 3, 8}};
        printf("%d", num[3][3]);
        break;
      }
    }
    i get this when i compile it

    Code:
     Æ@DDK5LN1X ~
    $ gcc 56.c
    56.c: In function `main':
    56.c:14: error: parse error before '{' token
    56.c:18: error: parse error before '{' token
    56.c:22: error: parse error before '{' token
    56.c:26: error: parse error before '{' token
    56.c:30: error: parse error before '{' token
    56.c:34: error: parse error before '{' token
    56.c:38: error: parse error before '{' token
    56.c:42: error: parse error before '{' token

    sorry for such a newbie question and program All it is doing is randomly showing the possible answers to a 3x3 magic square according to the random number that is generated and inserted into int a.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    You can not give new values to arrays, using the {}-operators. You can only do that, when you're initializing. You've to use the =-operator explicit.

    Code:
    num[3][3] = 8; // Allowed
    num[3][3] = {{8, 1, 6}, {3, 5, 7}, {4, 9, 2}}; // Disallowed

  4. #3
    siren is offline Newbie
    Join Date
    Apr 2007
    Posts
    10
    Rep Power
    0
    thank you v0id for helping me everytime!!! It's always very helpful and I learned what I was doing wrong, but it still isn't working. This is what I've changed so far..
    Code:
    #include<stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    main()
    {   
      int a,i,j;
      int num[2][2];
      srand((unsigned)time(NULL));
      a = rand() % (7 + 1);
     
      switch(a){
      case 0:
        num[0][0]=8;
        num[0][1]=1;
        num[0][2]=6;
        num[1][0]=3;
        num[1][1]=5;
        num[1][2]=7;
        num[2][0]=4;
        num[2][1]=9;
        num[2][2]=2;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;
      case 1:
        num[0][0]=4;
        num[0][1]=3;
        num[0][2]=8;
        num[1][0]=9;
        num[1][1]=5;
        num[1][2]=1;
        num[2][0]=2;
        num[2][1]=7;
        num[2][2]=6;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;
        
      case 2:
        num[0][0]=2;
        num[0][1]=9;
        num[0][2]=4;
        num[1][0]=7;
        num[1][1]=5;
        num[1][2]=3;
        num[2][0]=6;
        num[2][1]=1;
        num[2][2]=8;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;
      case 3:
        num[0][0]=6;
        num[0][1]=7;
        num[0][2]=2;
        num[1][0]=1;
        num[1][1]=5;
        num[1][2]=9;
        num[2][0]=8;
        num[2][1]=3;
        num[2][2]=4;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;
      case 4:
        num[0][0]=6;
        num[0][1]=1;
        num[0][2]=8;
        num[1][0]=7;
        num[1][1]=5;
        num[1][2]=3;
        num[2][0]=2;
        num[2][1]=9;
        num[2][2]=4;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break; 
      case 5:
        num[0][0]=8;
        num[0][1]=3;
        num[0][2]=4;
        num[1][0]=1;
        num[1][1]=5;
        num[1][2]=9;
        num[2][0]=6;
        num[2][1]=7;
        num[2][2]=2;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;  
      case 6:
        num[0][0]=4;
        num[0][1]=9;
        num[0][2]=2;
        num[1][0]=3;
        num[1][1]=5;
        num[1][2]=7;
        num[2][0]=8;
        num[2][1]=1;
        num[2][2]=6;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;
      case 7:
        num[0][0]=2;
        num[0][1]=7;
        num[0][2]=6;
        num[1][0]=9;
        num[1][1]=5;
        num[1][2]=1;
        num[2][0]=4;
        num[2][1]=3;
        num[2][2]=8;
        for(i=0;i<2;i++){
          for(j=0;j<2;j++){
    	printf("%3d",num[i][j]);}}
        break;
      }
    }
    the program runs fine, but it only outputs one number. I really don't know how I can output the whole matrix...sorry for so many questions

  5. #4
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    I've responded to your other thread. In the response I provided an example, including how to fill and print matrices.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Finding Expert in J2ME and PBASIC (Urgent)
    By firearth in forum Java Help
    Replies: 2
    Last Post: 01-03-2010, 02:54 PM
  2. finding in between date
    By prashant6388 in forum Database & Database Programming
    Replies: 1
    Last Post: 12-11-2009, 02:11 PM
  3. Pls help me, urgent very urgent. no joke.
    By salvate_me in forum C and C++
    Replies: 7
    Last Post: 10-10-2009, 07:26 PM
  4. Help finding an error?
    By Relo in forum C and C++
    Replies: 13
    Last Post: 10-09-2008, 07:19 AM
  5. Finding a DLL
    By Cosmet in forum C and C++
    Replies: 1
    Last Post: 02-13-2007, 09:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts