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; Maybe have a go at the psp-programming.com 'getting started' tutorials, they go through the basics, you can then build from ...
-
08-18-2007, 09:33 PM #6151
Maybe have a go at the psp-programming.com 'getting started' tutorials, they go through the basics, you can then build from there.
-
08-18-2007, 11:10 PM #6152
try it. I think thats right.
Zitat von MaTiAz
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-19-2007, 01:35 AM #6153QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Finland
- Beiträge
- 752
- Points
- 7.385
- Level
- 57
- Downloads
- 0
- Uploads
- 0
I've used paths like ms0:/PSP/PHOTO/ many times and they've all worked with only one slash. I've never bothered trying to use backslashes, but it's definitely the other way around when you're sprintf'ing paths (like ms0:/ requires no escape characters but ms0:\ requires another \).
Zitat von pspballer07
wheeee =:D
-
08-19-2007, 01:40 AM #6154QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
i always use / and it works perfect
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-19-2007, 02:25 AM #6155Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
a file got always hexadecimales , like 0xFF , that a character cant handle
but i need to make a if statement like this
//read data of file x to y
//if y[0x08] == 0xFF
with wich type do I do that?
-
08-19-2007, 10:02 AM #6156
ok well i'll fix my post
Zitat von MaTiAz
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-19-2007, 10:48 AM #6157QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Only a backwards OS (i.e. Windows) uses backslashes :) . Just use forward slashes on the PSP.
-
08-19-2007, 11:55 AM #6158
long int.
Zitat von hallo007
-
08-19-2007, 12:27 PM #6159QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Going by those two things I highlighted in bold, I assume you are reading 1 byte at a time. In that case, use type char. a character CAN handle 0xFF without losing any data. :\ 0xFF is the highest a char can handle.
Zitat von hallo007
Why is that? If he is checking 1 byte at a time, then an unsigned char would be sufficient.
Zitat von Mr305
[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]
-
08-19-2007, 01:25 PM #6160I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Say I make a file called global.c and store all my global variables inside it, could I then in the makefile type global.o to allow all my other files access to these globals? I've not used globals often before, and I don't feel like messing up any code just to test this theory.
Thanks.
-Aura
-
08-19-2007, 02:10 PM #6161
what i did for global vars for all .c files to use is did this:
Zitat von Auraomega
global.h
global.cCode:typedef struct Global { //put all global vars here float Varf; }; extern Global global;
which u can use it like this:Code:#include "global.h" Global global;
then u would add global.o to ur makefileCode:global.Varf = 1.0f;
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-19-2007, 02:21 PM #6162I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Ah cheers, this will certainly save having to use globals all in the same file (which is what scared me away from doing it in the past).
Thanks.
-Aura
-
08-19-2007, 02:24 PM #6163QJ Gamer Blue
- Registriert seit
- Feb 2007
- Ort
- Florida
- Beiträge
- 214
- Points
- 4.031
- Level
- 40
- Downloads
- 0
- Uploads
- 0
Noobish question time:
I'm using printTextScreen, and I want to be able to print the value of a function on the screen.
(Ex: if LinkLevel = 1, I want to display this on the screen: Level: 1).
I couldn't figure out how to do this, and I even looked at some tutorials...Help?
Heres what I tried:
printTextScreen(3, 3, "Level: %LinkLevel", RGB(255, 255, 255));
And obviously...That's not how you do it.
Help?
-
08-19-2007, 02:27 PM #6164I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
You have to sprint the values (lets PLEASE PLEASE refrain from another big argument...)
Zitat von MrChaos
Hope that helpsCode:char text[10]; sprintf(text, "Level: %d", LinkLevel); printTextScreen(3, 3, text, RGB(255, 255, 255);
-Aura
-
08-19-2007, 02:33 PM #6165QJ Gamer Blue
- Registriert seit
- Feb 2007
- Ort
- Florida
- Beiträge
- 214
- Points
- 4.031
- Level
- 40
- Downloads
- 0
- Uploads
- 0
Woked perfect. Thanks. :)
Zitat von Auraomega
-
08-19-2007, 02:49 PM #6166QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Code:... #include <stdarg.h> ... int screenPrintf(int x, int y, unsigned int color, char* text, ...) { char buffer[256]; va_list ap; // Pointer To List Of Arguments va_start(ap, text); // Parses The String For Variables vsprintf(buffer, text, ap); // Converts Symbols To Actual Numbers va_end(ap); // Results Are Stored In 'buffer' printTextScreen(x, y, buffer, color); return 0; } ... screenPrintf(0, 0, GU_RGBA(0, 0, 255, 255), "Hello %s!", "World");
-
08-19-2007, 03:26 PM #6167I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Hmm, I'm having problems with the extern thingy, when I try and compile I get
Any ideas what I've done wrong, baring in mind I only copied what you typed (so its most likely the way I'm linking the files)?
Zitat von Cygwin
-Aura
-
08-19-2007, 03:56 PM #6168Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
if you want to use globals, just use them the normal way. (declare them outside all functions, including main.) they're underrated. as long as you dont have like 5 billion (hyperbole), you'll be fine.
--------------------------------------------------------------------------------------
-
08-19-2007, 03:59 PM #6169I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Thats all fine except I'm using globals over 5-6 different files, doing this does not allow them to be declared in the normal way.
Zitat von Grimfate126
-Aura
-
08-19-2007, 07:12 PM #6170
did you put this in all the files?
Zitat von Auraomega
Code:#include "global.h"
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-19-2007, 08:10 PM #6171
This variable length arguement list stuff is pretty cool, I knew it was possible but had never tried it. Thanks for the example.
Zitat von _dysfunctional
About all the globals, are they constants? If not its much better to keep regular variables local.
Maybe rather than containing them all in a seperate file, you could contain them all in a structure like pspballer07 said, except then you could just pass a pointer to the globals to any function that needs them. Even that is pretty messy.
Have a search for the 'principle of least privilege', it explians why it's a good idea to only allow code to see data that it requires but nothing else. Trying to follow it can save you alot of time finding bugs :).
-
08-20-2007, 12:14 AM #6172QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Heavy use of globals is considered bad programming practice due to the amount of maintenance and extra debugging needed when something goes wrong. It also breaks encapsulation and promotes heavy coupling between code modules.
Strictly speaking, globals shouldn't be needed at all with C and C++ and you should pass the variables needed by parameter.
http://c2.com/cgi/wiki?GlobalVariablesAreBad
http://c2.com/cgi/wiki?GlobalVariablesConsideredHarmful[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
08-20-2007, 02:34 AM #6173Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
Zitat von Moca
Code:char y = 0xFF; if(y == 0xFF)
translationCode::290: let op: vergelijking is altijd vals omwille van het beperkte bereik van het datatype
so why does the compiller say that then?Code:warning : statement is always false because of the limit of the data type
-
08-20-2007, 02:49 AM #6174
it needs to be an unsigned char data type if your using values between 0 - 255
Zitat von hallo007
char data types range is -128 to 127
-
08-20-2007, 02:57 AM #6175QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
char is 0-255. It is unsigned by default.
The problem is that the compiler sees you trying to assign an int to a char so it assumes you are giving it a value out of range of a char.
Try:
Code:// C char blah = (char)(0xFF); // C++ char blah = static_cast<char>(0xFF);
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
08-20-2007, 03:02 AM #6176
i got my char info from here
Zitat von yaustar
http://www.eee.bham.ac.uk/dsvp_gr/ro...e3/tsld003.htmGeändert von brethren (08-20-2007 um 03:14 AM Uhr)
-
08-20-2007, 03:09 AM #6177Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
unsigned char works perfect for me , thnx=)
-
08-20-2007, 03:13 AM #6178
no problem, hallo007
-
08-20-2007, 03:29 AM #6179QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
now we are about unsigned so what exactly does it mean?
unsigned int for example or unsigned char ... when do you use it[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-20-2007, 03:32 AM #6180QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Just checked with my debugger, looks like I was wrong and got confused with the extended ASCII table. char's range is actually -127 to 127.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]


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