I wasn't sure exactly how to phrase this, but I have a char array of 50 where the first say 5 characters are my specified string (int this case "adder") and the 45 others are 0 (NULL). When I use commands such as printing to the console it like temporarily disables it or something. Note: I am developing for PS3
Example:
1 2 3 4 5 6 7 8 9
ConsoleWrite(myBuffer); //prints the 5 specified characters
ConsoleWrite(myBuffer); //doesn't print anything
ConsoleWrite("test"); //doesn't print anything
TestFunction(myBuffer); //runs TestFunction seemingly like myBuffer is null. If I had called this first before any ConsoleWrite it would have the same affect
//somewhere else outside of this function but being called after this function was called
ConsoleWrite("test"); //works fine
ConsoleWrite("test 2"); //works fine
TestFunction("adder"); //works fine
I am stumped. My program isn't crashing it just seems to have an effect as if it were reaching an exception and breaking but at the same time not breaking and just leaving out that single line of code or something.
This is my first post on the c++ forums in 2 years so show me you guys can help!
@helios ConsoleWrite() is not a built in function. It is actually a syscall, and it works as expected when not using an array as described in the question. Nevertheless, I have managed to get it printing correctly using printf but it still doesn't work with the Test Function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void SpawnVehicle(char str[]) {
int vehicle = CREATE_VEHICLE(str);
while (int i = 0; i < 5000; i++) {
if (vehicle == 0)
int vehicle = CREATE_VEHICLE(str);
elsebreak;
sleep(1);
} else {
print("Vehicle Not Spawned!"); //print is a method that draws text on the screen. not usually used for debugging
return;
}
print("Vehicle Spawned!");
}
The CREATE_VEHICLE(char *str) function spawns a vehicle with the given id. If the id is invalid it will never spawn.
So say we have out myBuffer
char myBuffer[50];
and then we clear myBuffer then place "adder" into myBuffer
1 2 3
for (int i = 0; i < 50; i++)
myBuffer[i] = 0;
strcpy(myBuffer,"adder");
So now I have tested using printf and myBuffer correctly prints out "adder"
FYI adder is a proper vehicle type and I use SpawnVehicle(char *) in other parts of code correctly
So now when I call
SpawnVehicle(myBuffer);
It loops through it many times and then prints "Vehicle Not Spawned!"
That's odd. I meant to write "the console may be line-buffered, so it may not flush [...]". I don't know why it came out like I knew for certain that it is buffered.
Is it possible that you're doing something silly, such as
1 2 3 4 5 6 7 8 9 10 11
char *foo(){
char myBuffer[50];
for (int i = 0; i < 50; i++)
myBuffer[i] = 0;
strcpy(myBuffer,"adder");
return myBuffer;
}
//...
ConsoleWrite(foo());
Then maybe it is null. Are you certain that myBuffer doesn't get modified in/after the call to ConsoleWrite()? Helios showed one way that could easily happen.