C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von head_54us I still think he is under allocating as he is explictly allocating 4 bytes for the string ...
-
12-17-2006, 03:41 PM #2371Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
You may be right, but I'm pretty sure that as long as he doesn't try to modify the contents, it should work. I'd think the compiler would raise warnings if it wasn't valid. Apparently that's not the case.
Zitat von head_54us
-
12-17-2006, 03:46 PM #2372QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Missing ; at the end of the code line. Should beCode:if (ourImage) { //Image load unsuccessful printf("Image Load Unsuccessful! \n") } else
-= Double Post =-Code:if (ourImage) { //Image load unsuccessful printf("Image Load Unsuccessful! \n"); } else
Zitat von Samstag
This threw up a compiler error on DevKitPSP. I am surprised it was okay on that code was posted up. Maybe it was with the older PSPDEV SDK?Code:char Nuts[4] = "defg";
Geändert von yaustar (12-17-2006 um 03:46 PM Uhr) Grund: Automerged Doublepost
-
12-17-2006, 03:56 PM #2373Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
That should be a GCC issue rather than being PSP-specific, but I guess it's possible an older psp-gcc let that through. Maybe the original poster only got a warning and didn't mention it? I don't see a lot of people posting warnings when they ask for help (heck, I know professionals who might ignore a warning if they don't see an immediate problem).
Zitat von head_54us[code
-
12-17-2006, 04:18 PM #2374QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Possibly. It does seem odd behaviour from the compiler though.
Zitat von Samstag
Where I work, we don't get that luxury, all warnings are treated as errors in our builds.
-
12-17-2006, 05:00 PM #2375QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Thanks a lot. I always make those kinds of mistakes :P.
Zitat von head_54us
It is either a spelling or one of those:ROFL: . Other than that, my code is usually fine.
[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
12-17-2006, 08:13 PM #2376words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Moca - I somehow doubt your priorexperience in C++ if you dont understandone of the msot common of errors the compiler spits out. But, i may be wrong and you just have never encountered such an error, but it doesnt matter in the end (although the error is self explanatory)

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
12-18-2006, 02:30 PM #2377
- Registriert seit
- Nov 2006
- Beiträge
- 11
- Points
- 3.593
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Nope, I would have caught it if there was an error. I am almost sure my compiler did not issue an error, but I might be wrong. I am using cygwin by the way.
Zitat von Samstag
EDIT: I tested it out agian, char test1 [4] = "1000"; made my glitch that I posted previously, but had no warnings in cgywin. char test1 [1] = "1000";, however, made a warning
Anywho, I ran into another problem; how do I split a string into multiple parts in C?
ex:
char test[8] = "Test";
How would I break apart the string into individual charactors (T, e, s, and t)? I want to use something like "if the second letter of string test equals e, then"
And is there a command to determine the length of the string? Does something like length(test) exist? (I don't want the length of the array of characters, I just want the length of the string held by test, which is "Test", which should be 4)
-
12-18-2006, 03:06 PM #2378words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
zwnage - It already is. A string is an array of characters, and your asking for how to get a character.
Simply provide the argument/parameter with whatever element the charactere is in.
ex:
char Test[8] = "Test";
if (Test[1] == 'e') { this will execute }
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
12-18-2006, 06:07 PM #2379Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
int length = strlen(Test);
Zitat von zwnage
-
12-19-2006, 12:38 PM #2380Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
some question about printtexttoscreen
if you wanne do a "\n" in printf but you are using print , how many pixels will you need to go down?? ,
one space how many pixels need that???
thnx in advance;)
-
12-19-2006, 01:56 PM #2381The Unique Developer

- Registriert seit
- Oct 2006
- Ort
- Canada
- Beiträge
- 1.059
- Points
- 7.101
- Level
- 55
- Downloads
- 0
- Uploads
- 0
printtexttoscreen is not like printf :) as you know your self
Zitat von hallo007
params -->
Hope I helped :)Code:printTextScreen(int x, int y, const char* text, u32 color); /* @param x: the starting position of the text (x-Coordinate) @param y: The level of the text on the screen (y-Coordinate_ @param text: The text to be written. @param color : a Color if your not using RGB mode simply use hex color (example black = 0x000000) Stil confused ? --> /** * Print a text (pixels out of the screen or image are clipped). * * @param x - left position of text * @param y - top position of text * @param text - the text to print * @param color - new color for the pixels */ */
there is no code for a new line just add 10+ to y current position of the text :)Malloc.Us Network Administrator
Decryption of the Encrypted
You are the unseen, the unstoppable and in power of your code. The God of your software.
-
12-19-2006, 10:07 PM #2382QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
This program compiles right that I made, but whe I run it, it doesnt operate exactly how I want. It does what its supposed to do, but it also does something very irritating. The text continuously repeats when I hold a button. Dont attack. I just started to code yesterday :P
Anyways, heres some screenshots with IR-SHELL of what happens.
Spoiler for Pictures of What is happening:
Spoiler for Code Stuff:[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
12-19-2006, 11:57 PM #2383Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
It's because the sensitivity of the controls is very high. What you deem as one keypress may well be 8 or more to the PSP.
The solution is to use the old faithful 'lastpad' method, like so (with comments):
Spoiler for Correct Code:
A few tips. There's no need for the 'break' statements, you could have just set 'done = 1'. On a similar note, 'while(!done)' reads better than what you have currently.
Learn to indent code correctly, it helps you read your code and others who have to read it too and is generally good practise.
Finally you should check the return value of the sceIoRemove calls to ensure the file was deleted successfully.
Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
12-20-2006, 02:24 AM #2384Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
and one space how many pixels are that?
Zitat von the unique warrior
-
12-20-2006, 01:52 PM #2385QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Thank you so much for that. It works and now I can continue with my work.
Zitat von Insert_Witty_Name
BTW, I do indent. I use Bloodshed. It indents everything very nicely. You should see my code in Dev C++. Ooooh. Sexy. I usially comment every single line, but a lot of it was removed to make forum space. Thank you for your help. Now all I need to do it have better spelling. That is the reason for most of my errors because I type the entire code manually.
I truly appreciate your help. Thanks.[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
12-20-2006, 02:47 PM #2386The Unique Developer

- Registriert seit
- Oct 2006
- Ort
- Canada
- Beiträge
- 1.059
- Points
- 7.101
- Level
- 55
- Downloads
- 0
- Uploads
- 0
usage:
Zitat von hallo007
I Think now you know whats going on eh ;)Code:printTextScreen(10, 10, "This Text Is Written On The Screen As Its Shown HERE With The Spaces!", 0xff00ff); printTextScreen(i10, 20, "This Text Is Under The Other Line Of Text", 0x00ffff);
Malloc.Us Network Administrator
Decryption of the Encrypted
You are the unseen, the unstoppable and in power of your code. The God of your software.
-
12-20-2006, 03:41 PM #2387QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Ok, I need help. I dont know how to write a file to flash0. I already know how to delete. I want to be able to restore files.
Could someone write a baisic program that only writes a file to flash0. I tried looking through source codes, but there is too much stuff that I cant tell if it is needed or not.
What I am requesting is a simple file with the #include's, and the rest of the file.
Nothing else. I can manage from there. I was hoping you would only post what is needed to write a file. Thanks. :)[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
12-20-2006, 03:55 PM #2388likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
how can I use fillScreenRect with 50% transparent?
-
12-20-2006, 04:05 PM #2389Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You can't. But there is an example further back in this thread of a function that does the same that insert_witty_name gave me. Try searching ;)
Zitat von psphacker12.
-
12-20-2006, 10:44 PM #2390words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
SodR - Cant you just make a 32 bit RGBA value and have 50% transparency? Seems like that would work and I believe Ive done it before...

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
12-22-2006, 02:41 AM #2391QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Not with fillScreenRect. It only fills the framebuffer with the colorvalue and doesn't do any blending or similar. Just render a fullscreen rect (GU_SPRITES primitive) over the screen and enable blending.
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
12-22-2006, 03:15 AM #2392words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
I havent heard from you in a long... long...
...
long time... But anyways, thanks for clearing that up, I guess I was just using an image with half transprency.
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
12-22-2006, 04:08 AM #2393QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Time is short and there's already few of it. Too few to enjoy all the goods of life at the same time (coding, games and girls ;P).
PS: I think there should be a special FAQ thread for all those graphics.c questions, they are always the same. Or even better, someone should change a lot of the graphics.c library to be more newb-friendly (and faster at the same time... I still can't believe someone coded direct framebuffer access to clear the screen on PSP).Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
12-22-2006, 04:59 AM #2394words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Hmm... Not havinga PSP, I suppose I now have time to think about what you said... True time is short, and that brought me to googling time travel months ago, I found out that astronauts traveling to the moon are going nano-seconds into the future... Since, as you get closer to the speed of light, time slows down.
But back on topic... Isn't the graphics library already GU accelerated, the parts that arent,Im sure someone wanting to could easily make it GU accelerated... Unless theres a more efficient way (Media Engine is for sound any sound card activity (or some variation of that statement) right? I never got into using it when I had a PSP)...
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
12-22-2006, 06:16 AM #2395Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
this just shows black screens
Spoiler for code:
-
12-22-2006, 06:54 AM #2396QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Digging into the world of relativity theory can either harm or charm you, depending on your view of "reality". Really worth trying to understand though, I can just recommend reading up on it.
What you talked about though is not really time travel, the astronauts just have a trip that takes them x.0000 seconds (by the means of a clock they carry with them), while when they return on earth x.0001 seconds have passed already (a clock on earth), so they basically are younger - which is a kind of time travel from their point of view, but that's what the relativity theory is all about - points of view.
Real time travel is only possible through wormholes (or black holes in a selfdestructive way), at least by theory. Not without all the time-paradox mess though, so don't try it at home ;P
To get back to topic: The graphics.c library makes spare use of GU every then and when, but not consistently and therefore lacks things like the transparent fill, where it could be possibly with a true GU implementation. The problem is that the library wasn't really layed out newb-friendly, but used in a newb tutorial. Well, anyways, someone just put together the quirks of the graphics.c library and make up a FAQ for all those starters questions :P
I need to talk to IWN, he wanted to start an improved version of the library way back on psp-programming.com.
@hallo007: you use redundant else if cases.
inthe else case already contains the !adaptor case, as that's exactly what else means.Code:if (adaptor) { } else { }
Also, your battery check does not care for the == 50 case and will then return with a "no battery" message. Fix that.
Also, you need to call initGraphics() before you do anything with that graphics.c library, though that will only set one stupid variable to true and nothing else. Another point for the FAQ :/ I start disliking that library more and moreRaphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
12-22-2006, 11:51 AM #2397
Using C, how would I fix issues with returning char values from a function?
I've been using char function() w/char* returns and it hasn't worked then I've used
char *key;
char *function() w/return( key); and it crashes.
But!
char *function()
{
char key[99];
return(key);
}
works, but I've seen many issues concerning char return values and would like to know which route really works and works best?
-
12-22-2006, 12:07 PM #2398Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
I thought you would get a warning saying returning address of local pointer or something with that, and then the content of it would be unavailable? I may be wrong, but I really think you would.
Zitat von Devun_06
you could do like,
char *function(char *key)
{
return key;
}
that should work.
-
12-22-2006, 12:21 PM #2399
o_O and that makes any sense ?
Zitat von Waterbottle
You have to allocate memory in the function dynamically via malloc (c) or new (c++)
By now the string will be deleted when the function returns, but at the time of returning the string is still there, then if you try to access that pointer -> pang!
-
12-22-2006, 01:25 PM #2400Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
what I meant was,
Zitat von tommydanger
int main()
{
char key[20];
function(key);
}
char *function(char *key)
{
sprintf(key, "hi");
return key;
}
that works, seeing as you pass the address of key to function and then it modifies the content of it and returns the same address..
and I'm aware that my explaining skills are horrible...


LinkBack URL
About LinkBacks
Mit Zitat antworten




Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum