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; Ok, iv got past that error showing when writing files but now the program runs fine but nothing is written ...
-
01-07-2008, 05:44 AM #7411QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Ok, iv got past that error showing when writing files but now the program runs fine but nothing is written at all
Probably another stupid thing iv missed. Any help would be great, thanksCode:pspDebugScreenInit(); char file_data[5]; char contents[5]; sprintf(file_data, "hello"); int file = sceIoOpen("ms0:/file.txt", PSP_O_WRONLY, 0777); if(file > 0)printf("File Opened\n"); if(file <= 0) { printf("Failed Opening File, Exitting"); sceKernelDelayThread(1000000); sceKernelExitGame(); } sceKernelDelayThread(1000000); int write = sceIoWrite(file, file_data, 5); if(write > 0)printf("Data Written to file\n\n"); if(write <= 0) { printf("Failed Writing to File, Exitting"); sceKernelDelayThread(1000000); sceKernelExitGame(); } sceKernelDelayThread(1000000); printf("Reading file contents\n"); sceIoRead(file, contents, 5); sceKernelDelayThread(1000000); printf("File contents: %s\n\n", contents); sceKernelDelayThread(3000000); printf("Exitting in:\n"); sceKernelDelayThread(1000000); printf("3...\n"); sceKernelDelayThread(1000000); printf("2...\n"); sceKernelDelayThread(1000000); printf("1...\n\n"); sceKernelDelayThread(1000000); printf("See Ya...\n"); sceKernelDelayThread(1000000); sceKernelExitGame();
EDIT: Found and fixed problem
Geändert von Xsjado7 (01-07-2008 um 06:16 AM Uhr)
-
01-07-2008, 12:30 PM #7412
HI guys I've got the following C struct:
I'm trying to populate it's members using:Code:struct songinfo { char filename[256]; char artist[64],song[64]; /* Song info, from ID3 */ int year; } s;
s.filename = tune;
OR
strcpy(s->filename,tune);
But I always get "incompatible types in assignment" even if I try like
s.filename = "test";
What could I be doing wrong on that?
Thanks,Placo23
Why not donate and become part of this selected list?Spoiler for Wanna see my Apps?:Spoiler for Donators:
-
01-07-2008, 12:57 PM #7413Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
try using typedef:
Zitat von placo23
Code:typedef struct { char filename[256]; char artist[64],song[64]; /* Song info, from ID3 */ int year; } SongInfo; SongInfo s; etc...--------------------------------------------------------------------------------------
-
01-07-2008, 01:02 PM #7414
Right, just did it, but am still getting exactly the same error.
Zitat von Grimfate126
Any other ideas?Placo23
Why not donate and become part of this selected list?Spoiler for Wanna see my Apps?:Spoiler for Donators:
-
01-07-2008, 01:28 PM #7415Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ah, i see why. "test" is a const char, and your array is made of chars, so thats why throwing the incompatible types error. use pointers instead.
Zitat von placo23
Geändert von Grimfate126 (01-07-2008 um 01:40 PM Uhr)
--------------------------------------------------------------------------------------
-
01-07-2008, 03:24 PM #7416QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Since you haven't told us what datatype variable tune is, we can't tell you the problem.
This should work however
If it doesn't then post up the actual code. There must be something else in the source that is causing that error.Code:strncpy( s.filename, "test", 255 );
[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]
-
01-07-2008, 03:31 PM #7417Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
wouldnt pointers be a better way to handle something dynamic such as this?
--------------------------------------------------------------------------------------
-
01-07-2008, 03:45 PM #7418QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
What is dynamic about strings?
[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]
-
01-07-2008, 04:15 PM #7419Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
dynamic as in he doesnt know the exact length of every song, so (i think) it would be better to make a char pointer instead of allocating a static array.
*gets ready to get pwned*--------------------------------------------------------------------------------------
-
01-07-2008, 04:16 PM #7420QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Well, filenames have a max length (256 bytes, IIRC) and ID3 tags also have a set amount of space set for song titles, so that is irrelevant.
-
01-07-2008, 04:38 PM #7421Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ah ok, forget my post then.
great, now im getting pwned by 2 people. >.<--------------------------------------------------------------------------------------
-
01-07-2008, 11:48 PM #7422
wat is the difference between signed and unsigned int?
i know that eg:
printf("&d&\n", 455);
printf("%u"\n", 455);
will show 455 then 65081 on the next line. but wat does of of this signed and unsigned mean and how does it work? ta in advance
-
01-08-2008, 02:01 AM #7423Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
http://www.space.unibe.ch/comp_doc/c...ata_types.html
Scroll down to see the range of values that can be stored in each data type.
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
-
01-08-2008, 02:20 AM #7424
I'm sorry for that, but that will be a string, in this case, the file name
Zitat von yaustar
Placo23
Why not donate and become part of this selected list?Spoiler for Wanna see my Apps?:Spoiler for Donators:
-
01-08-2008, 02:38 AM #7425QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Quick question, how do i go about checking the contents of a string? I read that you cant do it by:
Code:if(string == "something")
-
01-08-2008, 02:57 AM #7426QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
C++ strings, yes you can as they overload the == operator. C strings, you can't. Read: http://www.cppreference.com/stdstring/index.html
Zitat von Xsjado7
-= Double Post =-
Which is one of the reasons why I used strncpy instead of strcpy so he doesn't overrun the buffer.
Zitat von Grimfate126
If you use a char * and dynamically allocate the space for the string, you have to remember to free it and re-allocate it if the string length increases in size. More maintenence work to maintain the string. Static buffers are much easier to handle as they are always on the stack. You just have to be aware of buffer overruns.
The simplest solution is to use C++ strings. Much easier and cleaner.Geändert von yaustar (01-08-2008 um 03:00 AM Uhr) Grund: Automerged Doublepost
[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]
-
01-08-2008, 02:33 PM #7427I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
How do I use sceKernelExitVSHVSH properly?
From the header:
I believe that this function should allow me to restart the PSP (so to speak) loading another pspbtcnf.txt (or bin in newer firmwares) file. I have made param.configfile = "/kd/pspbtcnf_alt.bin" but with no success, the VSH just reboots reading from the original pspbtcnf.bin file. Does anyone here have any experiance with this, and/or can anyone see any problems with what I've done?Code:struct SceKernelLoadExecVSHParam { /** Size of the structure in bytes */ SceSize size; /** Size of the arguments string */ SceSize args; /** Pointer to the arguments strings */ void * argp; /** The key, usually "game", "updater" or "vsh" */ const char * key; /** The size of the vshmain arguments */ u32 vshmain_args_size; /** vshmain arguments that will be passed to vshmain after the program has exited */ void *vshmain_args; /** "/kd/pspbtcnf_game.txt" or "/kd/pspbtcnf.txt" if not supplied (max. 256 chars) */ char *configfile; /** An unknown string (max. 256 chars) probably used in 2nd stage of loadexec */ u32 unk4; /** unknown flag default value = 0x10000 */ u32 unk5; }; int sceKernelExitVSHVSH(struct SceKernelLoadExecVSHParam *param);
Thanks.
-Aura
-
01-09-2008, 07:16 PM #7428QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Hey guys,
This is a quick question, but how do you flip an image using OSLib? I couldn't find it in the documentations or the samples, and i could only find rotations and zoom, etc. I have a character facing right (my signature tells it all), but i want to make him face left using code.
Thanks.Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-09-2008, 07:54 PM #7429QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
As far as i know, you cant
-
01-09-2008, 09:04 PM #7430Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
you can. look carefully. i have used it before, and it works. I dont currently have oslib so i cant look for you, but im 100% sure its there.
--------------------------------------------------------------------------------------
-
01-09-2008, 09:41 PM #7431QJ Gamer Blue
- Registriert seit
- Aug 2007
- Beiträge
- 62
- Points
- 3.395
- Level
- 36
- Downloads
- 0
- Uploads
- 0
I have a question,
How would can I run another .PBP file in the same directory using C/C++?
Such as after EBOOT.PBP does something then it goes onto START.PBP or whatever name it would be.
-
01-09-2008, 09:59 PM #7432lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Search for it, their are tons of example's on running .PBP files.
-
01-10-2008, 08:30 AM #7433Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
You arent really supposed to request code here.
Zitat von DJKPSP
-
01-10-2008, 02:25 PM #7434
It's not that we don't do code requests, it's just that it'll help you be a better developer if you're able to search first. And this is very common, so you obviously didn't search.
Zitat von DJKPSP
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
01-10-2008, 03:32 PM #7435QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Speaking of searching...er, i still couldn't find a way i can flip an image (my signature into moving left not right). I did find one thing: the oslib samples of Mickey. I found out that you can flip Mickey by deforming him...kind of wierd but once you go past a point it works. However, i was wondering if there is an easier way.
Thanks.Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-10-2008, 04:38 PM #7436QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Hey, i just set up a function in my game that reads a config file to get controls. The config file contains something like this:
and then i have stuff like:Code:action=cross action2=square
Now i thought i could just read the config file, then use sprintf(); to print say, cross to action and square to action 2 and then go(with OSLib):Code:action_control[10]; action2_control[10];
But that didnt work because it expects either cross or square or circle and so on. So how would i go about using the string that contains the control specified by the user to control my game, any help would be great. Thanks(sorry for bad explaination)Code:if(osl_keys->pressed.action_control)do whatever; if(osl_keys->pressed.action2_control)do whatever;
Also, thanks Yaustar for that page. I got my problem all sorted out
-
01-10-2008, 04:56 PM #7437QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Well, how about doing this.
Options.txt file:
orCode:c
Where "c" is cross and "s" is square. Then, read the contents of the file:Code:s
At least, that's what i would do. There are a million ways to do it, and there are probably better ways.Code:/************************************************** Before While Loop ***************************************************/ //array for storing characters that will be read by txt file char xoptions[1]; //Delare file, and open FILE *options; if ((options = fopen("./options.txt","rb")) == NULL) { printf("Please Check Your Options.txt"); } //Store file contents into array xoptions[fread(xoptions, 1, 1, options)] = 0; //Close file fclose(options); /************************************************** While Loop ***************************************************/ //If array is c or s, then do whatever switch(xoptions[0]) { case 'c': if(osl_keys->pressed.cross) do whatever; break; //if cross, then do whatever case 's': if(osl_keys->pressed.square) do whatever; break; //if square, then do whatever }
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-10-2008, 05:09 PM #7438QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
yeah, thats the way i was going to do it but i have 12 options and 12 buttons used so i would have to go through every option and do something like:
...and so on to be compared with the string entered by user in config. Then:Code:char cross[10]; sprintf(cross, "cross"); char square[10]; sprintf(square, "square"); char triangle[10]; sprintf(triangle, "triangle");
and so on for every option using every buttonCode:if(strncmp(action_button, cross) { if(osl_keys->pressed.cross)do option1; } if(strncmp(action_button, square) { if(osl_keys->pressed.square)do option1; } if(strncmp(action_button, triangle) { if(osl_keys->pressed.triangle)do option1; }
If worse comes to worse il do it like that but i would prefer doing it another way
-
01-10-2008, 05:13 PM #7439QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
I'm still confused with your question. If you want to add more buttons, then put more "case"s. If you want to add more options, then make the array longer and read more characters. Also, if you have a bunch of "else if"s, then simply use switch and put your cases. It seems easier to me, especially when making menus.
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-10-2008, 06:24 PM #7440QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
How about searching information on C structs before asking retarded questions.


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