extern "C" bool R_CONTROLLER_API CreatePlayer(int num)
{
Player * Player1 = new Player(num);
listOfPlayers[num] = Player1;
return true;
}
extern "C" R_CONTROLLER_API char *ListPlayers()
{
static char string2return[500];
*string2return=0;
for( map
{
strncat(string2return, "test " + (*i).first, __min( 20, 500-strlen(string2return)) );
//params: char array, char array to append, number of chars to append
//__min returns the lesser of 2 numbers
}
return string2return;
}
Adam TurnerPosted Oct 22, 2008, 1:40 AM
extern "C" bool R_CONTROLLER_API CreatePlayer(int num)
{
Player * Player1 = new Player(num);
listOfPlayers[num] = Player1;
return true;
}
//a char array is the same as a char * in partiality, because they are both represented by a start at a certain memory address
extern "C" R_CONTROLLER_API char *ListPlayers()
{
ostringstream string2return;
static char buf[500];
*buf=0;
int count=1;
for( map
{
string2return << "Player: " << count /*(*i).first*/ << endl;
string2return << "Map Size: " << listOfPlayers.size() << endl;
count++;
//params: char array, char array to append, number of chars to append
//__min returns the lesser of 2 numbers
}
strcat(buf,string2return.str().c_str());
//concatenate a C style string with a char array
return buf;
}
AlanPosted Oct 19, 2008, 7:20 PM
Assuming it's a console app, I'd insert this line just before the C++ function returns to see what's actually in the string:
printf("%s"
, string2return);I can't see any obvious problem with the iterator which should print out successive player numbers preceded by "test ".
Adam TurnerPosted Oct 19, 2008, 3:02 PM
verb/Create_Player(var/n as num)
if(call("R_Controller.dll","CreatePlayer")(n))
usr<<"Player [n] created successfully."
verb/List_Players()
var/s = call("R_Controller.dll","ListPlayers")()
usr << "[s]" //essentially the same as cout <<
Create_Player() returns successfully. But List_Players() shows "est " only once, regardless of how many players are created.
I originally had List_Players() set up as just usr << call("R_Controller.dll","ListPlayers)(), but that acts the same.
So just adding another char to the string would solve my problem for the "est ", but perhaps the more disturbing glitch is the fact that the list is only iterated through once. Any ideas?
AlanPosted Oct 19, 2008, 11:38 AM
Well, I'd change this line:
static char string2return[500];
to this:
static char string2return[501];
to allow for the terminating null character which strlen doesn't include when calculating the length.
However, even as it stands, I can't see any reason why you're losing the first character of "test " in the function return value.
Are you sure that you're not losing it later when you print it out - perhaps printing from index 1 rather than index 0, something like that?