GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Aug-2006, 03:40
swedenguy swedenguy is offline
New Member
 
Join Date: Aug 2006
Posts: 8
swedenguy is on a distinguished road

how to initialize a char matrix matrix with empty elements?


hello guys!
i have a problem (don't know why) and need some help
I have a matrix se part of the code below
CPP / C++ / C Code:
int i, j;
	char matrix[3][3];
	for(i=0;i<=9; i++) {
		if(bo->square[i].piece_type==1) /*bo->square[i].piece_type return an integer */
			  matrix[i/3][i%3]='+';
		else if (bo->square[i].piece_type==2) /
			matrix[i/3][i%3]='*';
		else matrix[i/3][i%3]=' ';
		}
but i get a run time error when i have the last statement matrix[i/3][i%3]=' ';
If a remove this statement everything is correct but i get some strange (random character) at the empty matrix element when i print it on the screen
Can somebody tell me how do i intialize an element of the matrix with an empty character ' ' without geting this error ?
  #2  
Old 22-Aug-2006, 11:15
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: how to initialize a char matrix matrix with empty elements?


You specify your loop as:
CPP / C++ / C Code:
for (i = 0; i <= 9; i++)
(please use more whitespace to make your code readable as above)
During your last loop, what is the value of i? What does that do to your indecies?
CPP / C++ / C Code:
matrix[i/3][i%3] = '+';
What entry in matrix[?][?] are you accessing?
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Vectors and References Frankg C++ Forum 7 14-Jan-2006 06:17
Memory cannot be read? dlare9 C Programming Language 3 16-Nov-2005 07:03
Debug Assertion Failed! dlare9 C Programming Language 3 13-Nov-2005 23:18
Reading non ASCII with read() Atomical C Programming Language 8 13-Sep-2005 14:30
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 21:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:27.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.