Click here to Skip to main content
15,891,704 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WM_PAINT in View Pin
BryanBHU10-Jun-01 16:48
BryanBHU10-Jun-01 16:48 
GeneralRe: WM_PAINT in View Pin
Christian Graus11-Jun-01 0:33
protectorChristian Graus11-Jun-01 0:33 
GeneralRe: WM_PAINT in View Pin
Tomasz Sowinski11-Jun-01 3:01
Tomasz Sowinski11-Jun-01 3:01 
GeneralRe: WM_PAINT in View Pin
BryanBHU11-Jun-01 8:11
BryanBHU11-Jun-01 8:11 
GeneralRe: WM_PAINT in View Pin
Tomasz Sowinski11-Jun-01 0:22
Tomasz Sowinski11-Jun-01 0:22 
Generalmfc dll Pin
Nitish Kumar10-Jun-01 7:23
Nitish Kumar10-Jun-01 7:23 
GeneralRe: mfc dll Pin
Tim Deveaux10-Jun-01 12:46
Tim Deveaux10-Jun-01 12:46 
Generalchar* return problem Pin
10-Jun-01 4:01
suss10-Jun-01 4:01 
I have a problem regarding char*'s and character arrays....

Firstly to use strcat it seems I have to use a character array:
char ret[64] = "";
If I use a char* as the strcat argument it just doesnt like it!

But the function needs to return a char*. If I do;
return ret; (as declared above)
then I get an error (returning address of local variable).

I tried to get around this by doing:
char ret[64] = "";
char* tmp;
tmp = &ret[0];

This seemed to work fine, it passes the pointer, but when I try and cout
the value (ie cout << returnedValue; ) in my main function it just outputs
a load of garbage. I checked that the pointer is pointing to the right thing
before returning it and it is, so Im just thinking the area of memory could be
messed up in that short space of time...I have attatched the code in case im not
being clear!

Thanks
Any help appreciated

Code:


char* TicTacToe::formatForPrinting() {
char ret[32] = "";

for ( int rows = 0; rows < BOARD_SIZE; rows++ ) {
for ( int cols = 0; cols < BOARD_SIZE; cols++ ) {

if( gameBoard.position[rows][cols] == 1 ) {
strcat(ret,"X");
strcat(ret," ");
}
else if ( gameBoard.position[rows][cols] == 2 ) {
strcat(ret,"O");
strcat(ret," ");

}
else if ( gameBoard.position[rows][cols] == 0 ) {
strcat(ret,"-");
strcat(ret," ");
}
}

strcat(ret,"\n");
}

char* tmp;
tmp = &ret;

return tmp;
}


int main() {
// Create game object
TicTacToe* game = new TicTacToe;
char* b;

cout << "You are X, the board is currently:\n";
b = game->formatForPrinting();
cout << b << "\n";


return 0;
}
GeneralRe: char* return problem Pin
Stan Shannon10-Jun-01 4:12
Stan Shannon10-Jun-01 4:12 
GeneralRe: char* return problem Pin
10-Jun-01 4:29
suss10-Jun-01 4:29 
GeneralRe: char* return problem Pin
Stan Shannon10-Jun-01 5:11
Stan Shannon10-Jun-01 5:11 
GeneralRe: char* return problem Pin
Michael Dunn10-Jun-01 10:00
sitebuilderMichael Dunn10-Jun-01 10:00 
GeneralRe: char* return problem Pin
Masaaki Onishi10-Jun-01 4:58
Masaaki Onishi10-Jun-01 4:58 
GeneralAppending text in last ... Pin
Hadi Rezaee9-Jun-01 23:59
Hadi Rezaee9-Jun-01 23:59 
GeneralRe: Best way...? Pin
Masaaki Onishi10-Jun-01 5:11
Masaaki Onishi10-Jun-01 5:11 
GeneralRe: Best way...? Pin
Hadi Rezaee10-Jun-01 7:33
Hadi Rezaee10-Jun-01 7:33 
GeneralRe: Study by yourself! Pin
Masaaki Onishi10-Jun-01 12:39
Masaaki Onishi10-Jun-01 12:39 
GeneralCinternetSession Pin
Hushpappy9-Jun-01 23:58
Hushpappy9-Jun-01 23:58 
GeneralRe: CinternetSession Pin
l a u r e n10-Jun-01 3:43
l a u r e n10-Jun-01 3:43 
GeneralRe: Kill the connection? Pin
Masaaki Onishi10-Jun-01 4:23
Masaaki Onishi10-Jun-01 4:23 
GeneralComboBox Pin
9-Jun-01 23:31
suss9-Jun-01 23:31 
GeneralRe: ComboBox Pin
Stan Shannon10-Jun-01 0:59
Stan Shannon10-Jun-01 0:59 
GeneralRe: ComboBox Pin
10-Jun-01 1:59
suss10-Jun-01 1:59 
GeneralRe: ComboBox Pin
Stan Shannon10-Jun-01 2:04
Stan Shannon10-Jun-01 2:04 
GeneralRe: ComboBox Pin
10-Jun-01 2:09
suss10-Jun-01 2:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.