How can I make an array of character array pointers? I'm trying to achieve an array that holds 5 pointers to other arrays, with both arrays in structures. Here's what I have so far:
Oh dear, I forgot the compile log :)
The last error is on this line:
printf("%s%s%s",PieceArray[i]->LineArray[ii],PieceArray[i+1]->LineArray[ii],PieceArray[i+2]->LineArray[ii]);
main.cpp:94: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:95: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:96: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:97: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:98: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:100: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:101: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:102: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:103: error: cannot convert char (*)[10]' tochar*' in assignment
main.cpp:104: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:106: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:107: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:108: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:109: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:110: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:112: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:113: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:114: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:115: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:116: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:118: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:119: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:120: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:121: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:122: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:124: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:125: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:126: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:127: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:128: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:130: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:131: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:132: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:133: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:134: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:136: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:137: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:138: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:139: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:140: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:142: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:143: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:144: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:145: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:146: error: cannot convert char (*)[10]' tochar' in assignment
main.cpp:267: error: `LineArray' undeclared (first use this function)
main.cpp:267: error: (Each undeclared identifier is reported only once for each function it appears in.)
make.exe: *** [main.o] Error 1
Execution terminated
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Did a bit of reading - LineArray[5][10] declares a 5x10 "grid" so to speak. I now have a new problem:
Compiler: Default compiler
Building Makefile: "C:\mycstuff\console\FirstAttempt\Makefile.win"
Executing make...
make.exe -f "C:\mycstuff\console\FirstAttempt\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -Wall -Werror -Wformat
main.cpp: In function `int main(int, char**)':
main.cpp:212: error: LineArray' has not been declared
main.cpp:212: error: request for member of non-aggregate type before '[' token
main.cpp:212: error:LineArray' has not been declared
main.cpp:212: error: request for member of non-aggregate type before '[' token
main.cpp:212: error: `LineArray' has not been declared
main.cpp:212: error: request for member of non-aggregate type before '[' token
make.exe: *** [main.o] Error 1
Execution terminated
new structure:
struct piece
{
/ draw array /
char LineArray[5][10];
/ pos is the position of the piece /
int pos;
};
line 212:
printf("%s%s%s",PieceArray[i].LineArray[ii],PieceArray[i+1].LineArray[ii],PieceArray[i+2].LineArray[ii]);
PieceArray declaration:
struct piece Piece1,Piece2,Piece3,Piece4,Piece5,Piece6,Piece7,Piece8,Piece9,PieceArray[9];
PieceArray[0]=&Piece1;
PieceArray[1]=&Piece2;
PieceArray[2]=&Piece3;
PieceArray[3]=&Piece4;
PieceArray[4]=&Piece5;
PieceArray[5]=&Piece6;
PieceArray[6]=&Piece7;
PieceArray[7]=&Piece8;
PieceArray[8]=&Piece9;
I'm thoroughly confused.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ah.. I have fixed the problem.
I changed
printf("%s%s%s",PieceArray[i].LineArray[ii],PieceArray[i+1].LineArray[ii],*PieceArray[i+2].LineArray[ii]);
to
printf("%s%s%s",PieceArray[i]->LineArray[ii],PieceArray[i+1]->LineArray[ii],PieceArray[i+2]->LineArray[ii]);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> I'm sorry, I think I missed something; what exactly does char LineArray[5][10] ; declare?
I've never seen an array declared that way.
It is no magic and in fact quite common. It is a two dimensional array which it seems is what you were attempting to synthesize. You can have arrays with any number of dimensions (although more than three requires some spacial kind of brain to follow!)
An array of arrays if you like, LineArray is an array of five char[10] arrays for example.
How can I make an array of character array pointers? I'm trying to achieve an array that holds 5 pointers to other arrays, with both arrays in structures. Here's what I have so far:
Piece1 is a member of the structure
struct piece
{
char Line1[10],Line2[10],Line3[10],Line4[10],Line5[10],*LineArray[5];
int pos;
};
And this is the error I get:
cannot convert
char (*)[10]' to
char*' in assignmentI'm completely lost as to how I could achieve this.
-J.M
I'm learning off the Dev-Cpp help file... and pretty much making it up as I go along.
Thanks for the info on multi-dimensional arrays, I was wondering if you could do more than 2 dimensions.
-J.M
Oh dear, I forgot the compile log :)
The last error is on this line:
printf("%s%s%s",PieceArray[i]->LineArray[ii],PieceArray[i+1]->LineArray[ii],PieceArray[i+2]->LineArray[ii]);
Compiler: Default compiler
Building Makefile: "C:\mycstuff\console\FirstAttempt\Makefile.win"
Executing make...
make.exe -f "C:\mycstuff\console\FirstAttempt\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
main.cpp: In function `int main(int, char**)':
main.cpp:94: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:95: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:96: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:97: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:98: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:100: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:101: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:102: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:103: error: cannot convert
char (*)[10]' to
char*' in assignmentmain.cpp:104: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:106: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:107: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:108: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:109: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:110: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:112: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:113: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:114: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:115: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:116: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:118: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:119: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:120: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:121: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:122: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:124: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:125: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:126: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:127: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:128: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:130: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:131: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:132: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:133: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:134: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:136: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:137: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:138: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:139: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:140: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:142: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:143: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:144: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:145: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:146: error: cannot convert
char (*)[10]' to
char' in assignmentmain.cpp:267: error: `LineArray' undeclared (first use this function)
main.cpp:267: error: (Each undeclared identifier is reported only once for each function it appears in.)
make.exe: *** [main.o] Error 1
Execution terminated
char ** LineArray = new char * [5];
for (int i=0; i<5; i++) LineArray[i] = new char [10];
this also allows you to simplify
piece1.LineArray [i] [j]
Omit the &, the address of a char array hast type char**
Just:
Piece1.LineArray[0] = Piece1.Line1;
Although I cannot think why you would not simply have:
struct piece
{
char LineArray[5][10] ;
int pos ;
} ;
Clifford
I'm sorry, I think I missed something; what exactly does char LineArray[5][10] ; declare? I've never seen an array declared that way.
-J.M
Did a bit of reading - LineArray[5][10] declares a 5x10 "grid" so to speak. I now have a new problem:
Compiler: Default compiler
Building Makefile: "C:\mycstuff\console\FirstAttempt\Makefile.win"
Executing make...
make.exe -f "C:\mycstuff\console\FirstAttempt\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -Wall -Werror -Wformat
main.cpp: In function `int main(int, char**)':
main.cpp:212: error:
LineArray' has not been declared main.cpp:212: error: request for member of non-aggregate type before '[' token main.cpp:212: error:
LineArray' has not been declaredmain.cpp:212: error: request for member of non-aggregate type before '[' token
main.cpp:212: error: `LineArray' has not been declared
main.cpp:212: error: request for member of non-aggregate type before '[' token
make.exe: *** [main.o] Error 1
Execution terminated
new structure:
struct piece
{
/ draw array /
char LineArray[5][10];
/ pos is the position of the piece /
int pos;
};
line 212:
printf("%s%s%s",PieceArray[i].LineArray[ii],PieceArray[i+1].LineArray[ii],PieceArray[i+2].LineArray[ii]);
PieceArray declaration:
struct piece Piece1,Piece2,Piece3,Piece4,Piece5,Piece6,Piece7,Piece8,Piece9,PieceArray[9];
PieceArray[0]=&Piece1;
PieceArray[1]=&Piece2;
PieceArray[2]=&Piece3;
PieceArray[3]=&Piece4;
PieceArray[4]=&Piece5;
PieceArray[5]=&Piece6;
PieceArray[6]=&Piece7;
PieceArray[7]=&Piece8;
PieceArray[8]=&Piece9;
I'm thoroughly confused.
Ah.. I have fixed the problem.
I changed
printf("%s%s%s",PieceArray[i].LineArray[ii],PieceArray[i+1].LineArray[ii],*PieceArray[i+2].LineArray[ii]);
to
printf("%s%s%s",PieceArray[i]->LineArray[ii],PieceArray[i+1]->LineArray[ii],PieceArray[i+2]->LineArray[ii]);
> I'm sorry, I think I missed something; what exactly does char LineArray[5][10] ; declare?
I've never seen an array declared that way.
It is no magic and in fact quite common. It is a two dimensional array which it seems is what you were attempting to synthesize. You can have arrays with any number of dimensions (although more than three requires some spacial kind of brain to follow!)
An array of arrays if you like, LineArray is an array of five char[10] arrays for example.
http://en.wikipedia.org/wiki/Array#Multi-dimensional_arrays
http://www.exforsys.com/tutorials/c-language/c-arrays.html
> PieceArray[0]=&Piece1;
Looks like you are doing the same odd thing there! Why is PieceArray an array of piece pointers and not simply an array of piece objects?
If it does for some reason need ot be an array of pointers, then:
*PieceArray[i].LineArray[ii]
is more usually written:
PieceArray[i]->LineArray[ii]
It is unusual to dereference a struct pointer to access members rather than using the -> operator. Where are you learning this stuff!?
Clifford