Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-13-2007, 04:14 AM
siren siren is offline
Newbie
 
Join Date: Apr 2007
Posts: 10
Rep Power: 0
siren is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-13-2007, 06:06 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,415
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-13-2007, 07:59 AM
siren siren is offline
Newbie
 
Join Date: Apr 2007
Posts: 10
Rep Power: 0
siren is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-13-2007, 09:45 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,415
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

I've responded to your other thread. In the response I provided an example, including how to fill and print matrices.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB6.0:Tutorial, Error handling TcM VB Tutorials 9 06-06-2008 01:31 PM
Download problem, internal Server Error j3cubcapt ionFiles 1 07-02-2007 09:45 AM
Php - CGI Error thesquirrel16 General Programming 1 05-19-2007 05:09 PM
can someone help me with my c librarys? bobwrit C and C++ 4 04-27-2007 06:19 PM
Php error handling Jaan PHP Tutorials 1 03-01-2007 09:20 PM


All times are GMT -5. The time now is 11:44 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 66%

Ads