- #1
Dembadon
Gold Member
- 659
- 89
Homework Statement
I am making a Klondike style solitaire game, and I am trying to load a string into a 3D array. I am representing the "Tableau" with a 3D array (we haven't gone over structs yet). I want to represent the spaces which don't have cards with the word "empty". I'm not understanding how to copy a C-style string to a 3D array.
Homework Equations
My compiler, g++, is giving me the following error:
Code:
uploadTest.cpp: In function ‘void strCopy(char (*)[60][80], char*)’:
uploadTest.cpp:240: error: incompatible types in assignment of ‘char’ to ‘char [80]’
Here are my array declarations:
Code:
char emptyRow[ MAX_STR_LEN ] = "empty";
char tableau[ MAX_ROWS ][ MAX_COLS ][ MAX_STR_LEN ];
Here's how it is called:
Code:
strCopy( tableau, emptyRow );
The Attempt at a Solution
Code:
// prototype
void strCopy( char destArr[ MAX_ROWS ][ MAX_COLS ][ MAX_STR_LEN ],
char srcArr[ MAX_STR_LEN ] );
////////////////////////////////////////////////////////////////
// implementation
void strCopy( char destArr[ MAX_ROWS ][ MAX_COLS ][ MAX_STR_LEN ],
char srcArr[ MAX_STR_LEN ] ) {
// initialize function/variables
int colI = 0;
int rowIndex = 0, colIndex = 0;
// loop through source array
while( srcArr[ colI ] != NULL_CHAR ) {
// assign character
destArr[ rowIndex ][ colIndex ] = srcArr[ colI ];
// increment index
colI++;
}
}
Do I have to create a third index for the destArr and increment it? I tried doing this but the compiler still complained.