PSP Hacks - Forums

Go Back   PSP Hacks - Forums > PSP Community > PSP Programming & Development

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2009, 08:14 PM
madman666's Avatar
madman666 madman666 is offline
Programmer
PSP Newbie
 

Join Date: Aug 2009
Posts: 18
madman666 will become famous soon enough
Default oslDebug both text and variable in one line of code?

I am wanting to print both text and a veriable in the same print out. How is this done using oslib?

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
__________________
Reply With Quote
  #2  
Old 11-15-2009, 03:46 PM
MTN's Avatar
MTN MTN is offline
Programmer
PSP Hacks Member
 
Join Date: Jan 2009
Location: ...
Posts: 291
MTN Has a Beginner Reputation
Default

^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
<< only works with cout/cin (std::cout / std::cin in psp programming)
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.
Reply With Quote
  #3  
Old 11-15-2009, 07:39 PM
Stinkee2's Avatar
Stinkee2 Stinkee2 is offline
Programmer
PSP Hacks Member
 

Join Date: Jul 2009
Location: int main()
Posts: 280
Stinkee2 is on a distinguished road
Default

Quote:
Originally Posted by MTN View Post
EDIT: you can make your own function . to find out how to write it take a look at Stinkee2's EGPLib
or just ask me
Spoiler:

Code:
#include <stdarg.h>
char *ToString(const char *Text,...)
{
     va_list Args;
     va_start(Args,Text);
     char str[1001] = {'\0'};
     vsprintf(str,Text,Args);
     va_end(Args);
     return str;
}


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:

"Jesse, I need your supercapacitor!" - Ian Flournoy

"Fascism, pronounced fæʃɪzəm" - Wikipedia

Me: "Hang on, Im fertelizing the plant."
Dad: "My hand is gonna fertelize your ass in a minute!" - Dad (RIP)

Last edited by Stinkee2; 11-15-2009 at 09:01 PM.
Reply With Quote
  #4  
Old 11-15-2009, 11:00 PM
pspjoke's Avatar
pspjoke pspjoke is offline
Programmer
PSP Guru
 

Join Date: Mar 2008
Location: U.S.
Posts: 1,822
pspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to all
Default

Quote:
Originally Posted by Stinkee2 View Post
or just ask me
Spoiler:

Code:
#include <stdarg.h>
char *ToString(const char *Text,...)
{
     va_list Args;
     va_start(Args,Text);
     char str[1001] = {'\0'};
     vsprintf(str,Text,Args);
     va_end(Args);
     return str;
}


thats just from memory though because Im not at my laptop right now.
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.

Reply With Quote
  #5  
Old 11-16-2009, 03:31 PM
Stinkee2's Avatar
Stinkee2 Stinkee2 is offline
Programmer
PSP Hacks Member
 

Join Date: Jul 2009
Location: int main()
Posts: 280
Stinkee2 is on a distinguished road
Default

Quote:
Originally Posted by pspjoke View Post
shivers.. i feel a buffer over-run coming.
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:

"Jesse, I need your supercapacitor!" - Ian Flournoy

"Fascism, pronounced fæʃɪzəm" - Wikipedia

Me: "Hang on, Im fertelizing the plant."
Dad: "My hand is gonna fertelize your ass in a minute!" - Dad (RIP)
Reply With Quote
  #6  
Old 11-16-2009, 04:05 PM
pspjoke's Avatar
pspjoke pspjoke is offline
Programmer
PSP Guru
 

Join Date: Mar 2008
Location: U.S.
Posts: 1,822
pspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to allpspjoke is a name known to all
Default

Quote:
Originally Posted by Stinkee2 View Post
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.
lol i wouldn't have thought you were being a dick.

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;
}
i think. anyway, that should grantee a no overflow situation.
__________________
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.

Reply With Quote
  #7  
Old 11-16-2009, 06:13 PM
Stinkee2's Avatar
Stinkee2 Stinkee2 is offline
Programmer
PSP Hacks Member
 

Join Date: Jul 2009
Location: int main()
Posts: 280
Stinkee2 is on a distinguished road
Default

Quote:
Originally Posted by pspjoke View Post
was gonna say something here... don't remember what.
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:
Originally Posted by pspjoke View Post
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;
}
i think. anyway, that should grantee a no overflow situation.
Your a genious!
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:

"Jesse, I need your supercapacitor!" - Ian Flournoy

"Fascism, pronounced fæʃɪzəm" - Wikipedia

Me: "Hang on, Im fertelizing the plant."
Dad: "My hand is gonna fertelize your ass in a minute!" - Dad (RIP)
Reply With Quote
  #8  
Old 11-16-2009, 08:02 PM
madman666's Avatar
madman666 madman666 is offline
Programmer
PSP Newbie
 

Join Date: Aug 2009
Posts: 18
madman666 will become famous soon enough
Default

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.
__________________
Reply With Quote
  #9  
Old 11-17-2009, 12:39 AM
Brick Brick is offline
I am Flame Master
PSP Enthusiast
 

Join Date: Mar 2008
Location: *this
Posts: 464
Brick is on a distinguished road
Default

Quote:
Originally Posted by pspjoke View Post
lol i wouldn't have thought you were being a dick.

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;
}
i think. anyway, that should grantee a no overflow situation.
The result of the first example is undefined unless you make it static , but then if more than 1 ptrs point to it , they will contain the same data.

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.
Reply With Quote
  #10  
Old 11-17-2009, 04:47 AM
Stinkee2's Avatar
Stinkee2 Stinkee2 is offline
Programmer
PSP Hacks Member
 

Join Date: Jul 2009
Location: int main()
Posts: 280
Stinkee2 is on a distinguished road
Default

Quote:
Originally Posted by madman666 View Post
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.
Good luck programming .

@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:

"Jesse, I need your supercapacitor!" - Ian Flournoy

"Fascism, pronounced fæʃɪzəm" - Wikipedia

Me: "Hang on, Im fertelizing the plant."
Dad: "My hand is gonna fertelize your ass in a minute!" - Dad (RIP)
Reply With Quote
Reply

 



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:48 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©