![]() |
|
#1
|
||||
|
||||
|
I have tried using + and << and .. between the text and variable but I keep getting errors when I compile my code. these are the all different ways I have done this in other script language. for example I would like it say in a Debug message "Active Location X=0 Y=0" oslDebug("Active Location X=" + x + " Y=" + y); and oslDebug("Active Location X=" << x << " Y=" << y); and oslDebug("Active Location X=" .. x .. " Y=" .. y); all do not work. other then making a string and adding up all the parts, is there a easier way to do this? I have searched and have not found anything
__________________
|
|
#2
|
||||
|
||||
|
^works with a String class (with overloaded "+" operator) (which is not included in sdk)
you can use sceDebugScreenprintf("X=%i",x); . or if the functions doesnt have char format use : Code:
char *str; int a=10,b=20; sprintf(str,"%i x 2 = %i",a,b); oslDebug(str); //Result is : 10 x 2 = 20 i dont know any other way to do it ... EDIT: you can make your own function . to find out how to write it take a look at Stinkee2's EGPLib Last edited by MTN; 11-15-2009 at 03:50 PM. |
|
#3
|
||||
|
||||
|
Quote:
![]() Spoiler: thats just from memory though because Im not at my laptop right now.
__________________
----------------------------------------- ![]() The Real Brian Peppers (Told From Brother) =D By far my favorite quote ever: "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... Other Funny Quotes: Spoiler: Last edited by Stinkee2; 11-15-2009 at 09:01 PM. |
|
#4
|
||||
|
||||
|
shivers.. i feel a buffer over-run coming.
__________________
http://levoneprojects.net23.net/
![]() ++rep me if i helped you please. Ahh, shit. Stupidity is on the rise again. went legit Oct. 31, 09' piracy is wrong, please don't do it. |
|
#5
|
||||
|
||||
|
How would you have done it?
if that looks like im trying to be a dick thats not how I meant it, I'm just curious so that I can fix any problems with my code.
__________________
----------------------------------------- ![]() The Real Brian Peppers (Told From Brother) =D By far my favorite quote ever: "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... Other Funny Quotes: Spoiler: |
|
#6
|
||||
|
||||
|
Quote:
anyway, you just need to add some checks(at least) for your char array. arrays + pointers = dangerous if not handle correctly. your code for example. (with comments) Code:
#include <stdarg.h>
char *ToString(const char *Text,...)
{
va_list Args;
va_start(Args,Text);
char str[1001] = {'\0'}; //what if the Text pointer points to a longer string?
vsprintf(str,Text,Args); //possible over-run?
va_end(Args);
return str;
}
was gonna say something here... don't remember what. anyway i would do it like.. Code:
#include <stdarg.h>
#include <string.h>
char *ToString(const char *Text,...)
{
va_list Args;
va_start(Args,Text);
char* str = new char[strlen(Text)];
vsprintf(*str,Text,Args);
va_end(Args);
delete str;
return str;
}
__________________
http://levoneprojects.net23.net/
![]() ++rep me if i helped you please. Ahh, shit. Stupidity is on the rise again. went legit Oct. 31, 09' piracy is wrong, please don't do it. |
|
#7
|
||||
|
||||
|
were you going to say something about vsNprintf? I could have used that and set the size to 1000. I dont know why I didnt think to though.
Quote:
Why didnt I think of that?
__________________
----------------------------------------- ![]() The Real Brian Peppers (Told From Brother) =D By far my favorite quote ever: "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... Other Funny Quotes: Spoiler: |
|
#8
|
||||
|
||||
|
Thanks guys you helped alot.
this will be my first attempt at a C++ program. I have created stuff with Java and LUA(WOW Plug-ins). so overall the codding is going good as the basics are all the same its just the little things like the Strings and learning what I can do with the oslib that I have been hanging up on. I should have a working Alpha sometime tonight. Then Ill start working on the features.
__________________
|
|
#9
|
|||
|
|||
|
Quote:
The second example will crash because you delete the string. The most efficient approach is a buffered string class/library that will reallocate the buffer only when needed. |
|
#10
|
||||
|
||||
|
Quote:
.@Brick: Thanks, I will try that tomorrow.
__________________
----------------------------------------- ![]() The Real Brian Peppers (Told From Brother) =D By far my favorite quote ever: "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... Other Funny Quotes: Spoiler: |
![]() |
|
|
|||
|
|||
|
|
| Thread Tools | |
| Display Modes | |
|
|