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; You need that doc thingy thing for the pspsdk to install the docs though......
-
10-11-2006, 12:29 PM #1231AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
You need that doc thingy thing for the pspsdk to install the docs though...
-
10-11-2006, 01:16 PM #1232Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
To answer a few off the last posts....
Doxygen is that doc thingy ;)
'remove' or 'unlink' works fine.
The sceIo* functions are in at least one sample, see samples/kernel/fileio for one.
I'd recommend using the newlib variants though over the SDK versions.
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
-
10-12-2006, 04:41 AM #1233QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
hmm, what is newlib? Google doesn't really say much on this
-
10-12-2006, 04:45 AM #1234Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
http://en.wikipedia.org/wiki/Newlib
When I say newlib variants, I mean the regular stdio functions, see here:
http://www.cplusplus.com/ref/cstdio/
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
-
10-12-2006, 05:13 AM #1235
Can any one tell me what sceAudioOutputPannedBlock ing dose exacly
it is not documented and am currently using sceAudioOutputPanned for audio out, and need to now play longer sample files and was looking at this funtion sceAudioOutputPannedBlock ing and needed to know what it ment exacly by blocking.
-
10-12-2006, 05:38 AM #1236QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thanks Inso
Another short question, hope I'm not beginning to get on yer nerves:
Can you only free() variables that have been declared using xalloc? And, I'm pretty sure it is the case, but just wanna -know- it - do (non-static) variables get freed automatically at the end of a function?
-
10-12-2006, 05:49 AM #1237Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
You can only free allocated memory yes.
Variables declared within a function only exist until that function ends.
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
-
10-12-2006, 05:54 AM #1238QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
ThanksYou can only free allocated memory yes.
By now I find my question more than embarrassing.Variables declared within a function only exist until that function ends.
-
10-12-2006, 06:21 AM #1239
hehe i also had a few errors because of variables inside functions hehe
-
10-12-2006, 06:25 AM #1240QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
question on fgets: I read a file artists.txt which contains:
using this code1234567890
A perfect Circle
timestamp then contains "1234567890♪"Code:FILE *f = fopen("artists.txt", "r"); fgets(timestamp, 16, f); fclose (f);
How do I get rid of that last symbol?
PS: I wrote that file using windows, is that symbol probably a fragment of the widows-carriage-return?
-
10-12-2006, 06:31 AM #1241Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Yeah I seem to remember it's the \r or something.
Instead of saving the end of line as ending \n, it's saved as \r\n, or something like that.
Try it with a different editor, I seem to remember that one of the native Windows applications saves it how we need it.
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
-
10-12-2006, 06:31 AM #1242
it is a command to go to the next lin i think you can hex edit it away
-
10-12-2006, 09:24 AM #1243QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I am confused; I'm trying to send a list of artists that I read from a file via TCP to the PSP and save it there as a file again. The problem is, the transferred list isn't complete. Im having length-outputs in the server and the client, but it confuses me even more:
Server Code (read file and send string-length and contents):
Client code (recive length and contents and write to file):Code:pFile = fopen ( "artists.txt" , "rb" ); fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); buffer = (char*) malloc (lSize); fread (buffer,1,lSize,pFile); fclose (pFile); printf("Sending artist-list-length ("); sprintf(answer_l, "%i", strlen(buffer)); printf("%s)\n", answer_l); rc=send(sock,answer_l,strlen(answer_l),0); printf("Sending list of artists...\n"); if (rc=send(sock,buffer,strlen(buffer),0) != strlen(buffer)) { printf("send different lenghts; buffer=%i rc=%i\n", strlen(buffer), rc); } printf("sizeof(buf)=%i strlen(buf)=%i rc=%i\n", sizeof(buffer), strlen(buffer), rc);
The Server output is:Code:if((rc = recv(socket, artist_list_length_c, 8,0)) < 0) { printf("Error while recieving the artist-list-length; error-code: %s\n",strerror(errno)); return 0; } if(rc==0) { printf("Client has closed the connection before sending the artist-list-length\n"); return 0; } artist_list_length_c[rc]='\0'; artist_list_length = atoi(artist_list_length_c); artist_list_length++; char buf[artist_list_length]; // Recieve artist-list rc = recv(socket,buf,artist_list_length,0); if(rc==0) { printf("Server has closed the connnection before sending the artist-list\n"); return 0; } if(rc==SOCKET_ERROR) { printf("Error: recv, error-code: %s\n",strerror(errno)); return 0; } buf[rc]='\0'; printf("sizeof(buf)=%i strlen(buf)=%i\n", sizeof(buf), strlen(buf)); f = fopen("artists.txt", "w+"); fprintf(f, "%s\n%s", timestamp_server, buf); fclose(f);
The Client output is:Sending artist-list-length (5180)
Sending list of artists...
sizeof(buf)=4 strlen(buf)=5180 rc=0
I'm really confusedsizeof(buf)=5181 strlen(buf)=1448
PS: I checked the file on the PSP and visually judging it, it could be ~1448 chars
-= Double Post =-
Is there probalby a maximum length in send or recieve?
-= Double Post =-
Ok, I'll just accept that it doesn't work with such a long string (probably because you can't send a string longer than 1448 chars) so I'll have to split it. Does anyone know how to do this (split a string at X bytes)?
-= Double Post =-
Nevermind, it's easy to split strings.. afer all it's an array so that'll be no problem
-= Double Post =-
Can you somewhere find out what the current MTU is?
-= Double Post =-
The german wikipedia says typical MTU for ethernet is 1500... that could be it!
However I thought the socket would do the MTU/splitting-job?!Geändert von Lukeson (10-12-2006 um 09:25 AM Uhr) Grund: Automerged Doublepost
-
10-12-2006, 11:04 AM #1244AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Apparently not
Zitat von Lukeson
I don't know much about network/wifi coding so I won't be able to help
-
10-12-2006, 11:27 AM #1245QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
СУ&am from psp-programming.com answered this issue. You can send any length of bytes but that doesn't mean that you'll recieve it as one chunk. You have to use a loop and recive until recv returns 0.
-= Double Post =-
...but that doesn't mean it's the end of troubles! The output now is
and in the middle of the file there's a line likesizeof(recievedMessage)=5 181 strlen(recievedMessage)=8101
no idea whyÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ[...a thousand more...]ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿ
-= Double Post =-
^^ I forgot the code:
Code:printf("waiting to recieve artists\n"); // Recieve artist-list-length if((rc = recv(socket, artist_list_length_c, 8,0)) < 0) { printf("Error while recieving the artist-list-length; error-code: %s\n",strerror(errno)); return 0; } if(rc==0) { printf("Client has closed the connection before sending the artist-list-length\n"); return 0; } artist_list_length_c[rc]='\0'; artist_list_length = atoi(artist_list_length_c); artist_list_length++; char recievedMessage[artist_list_length]; char buf[artist_list_length]; // Recieve artist-list while(rc!=SOCKET_ERROR) { rc = recv(socket,buf,artist_list_length,0); if(rc==0) { printf("Server stopped sending\n"); break; } if(rc==SOCKET_ERROR) { printf("Error: recv, error-code: %s\n",strerror(errno)); break; } buf[rc]='\0'; strcat(recievedMessage, buf); } //recievedMessage[artist_list_length]='\0'; printf("sizeof(recievedMessage)=%i strlen(recievedMessage)=%i\n", sizeof(recievedMessage), strlen(recievedMessage)); f = fopen("artists.txt", "w+"); fprintf(f, "%s\n%s", timestamp_server, recievedMessage); fclose(f);Geändert von Lukeson (10-12-2006 um 11:27 AM Uhr) Grund: Automerged Doublepost
-
10-12-2006, 11:31 AM #1246QJ Gamer Blue
- Registriert seit
- Mar 2006
- Ort
- Michigan
- Beiträge
- 211
- Points
- 4.831
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Im trying to make my second actual program using this guide but I don't know what's wrong with my code. The guide isnt specific on where to put each string of code. Can someone help me out by re arranging my code so it works and just telling me what I did wrong please?
Code:#include <pspdebug.h> #include <pspkernel.h> #include <pspdisplay.h> #include <pspctrl.h> PSP_MODULE_INFO("Counter", 0, 1, 1); /* Exit callback */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { SetupCallbacks(); int counter = 0; int i = 0; SceCtrlData pad; printf("Press [X] To Start the Timer"); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { break; } } while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CIRCLE) { break; } pspDebugScreenInit(); pspDebugScreen sceKernelSleepThread(); printf("Press [O] To Stop the Timer\n"); printf("Counter: %i", counter); counter++; for(i=0; i<5; i++) { sceDisplayWaitVblankStart(); } pspDebugScreenClear(); printf("Counter Finished."); printf("Final Count: %i", counter); return 0; }Geändert von Nolimitsdude313 (10-12-2006 um 11:32 AM Uhr) Grund: Automerged Doublepost
-
10-12-2006, 11:32 AM #1247I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I'm trying to port my first C game to PSP. It's a very simple game, only like 2 pages of code. But I need to know the equivelent of fflush(); on the PSP. Does anyone know? Also, how do I make the PSP wait for any button to be pressed, then continue?

-
10-12-2006, 11:37 AM #1248QJ Gamer Blue
- Registriert seit
- Mar 2006
- Ort
- Michigan
- Beiträge
- 211
- Points
- 4.831
- Level
- 44
- Downloads
- 0
- Uploads
- 0
This guide explains how to make the psp wait for the button to be pressed. :)
-
10-12-2006, 11:41 AM #1249I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
OK, I see now. Now I just need my other question answered.
Zitat von Nolimitsdude313

-
10-12-2006, 11:46 AM #1250QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
psp-programming.com says there is fflush() in the PSPSDK...But I need to know the equivelent of fflush(); on the PSP.
-
10-12-2006, 11:48 AM #1251AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Yeah, the sdk has newlib. So fflush should be the same as on a Pc.
-
10-12-2006, 11:52 AM #1252QJ Gamer Blue
- Registriert seit
- Mar 2006
- Ort
- Michigan
- Beiträge
- 211
- Points
- 4.831
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Still need help with this
Zitat von Nolimitsdude313
-
10-12-2006, 11:57 AM #1253QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Does anyone have an idea why my psp freezes? http://forums.qj.net/f-psp-developme...ml#post1100739
Sorry for the nagging, but in this 1-thread-'solution' things are being forgotten so easily when they are not on the last page anymore
-= Double Post =-
Missing a }, check the tutorialCode:for(i=0; i<5; i++) { sceDisplayWaitVblankStart(); } pspDebugScreenClear(); printf("CounGeändert von Lukeson (10-12-2006 um 11:57 AM Uhr) Grund: Automerged Doublepost
-
10-12-2006, 11:58 AM #1254QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Here's the problem: You're using printf before pspDebugScreenInit(). You have to call this before doing anything with the output screen. Also, you have
Zitat von Nolimitsdude313
The second line is an incomplete command, and the third one needs an argument (the number of microseconds to sleep - e.g. 1000000 = 1 second). There might be more, but that's what I saw at a brief glance.Code:pspDebugScreenInit(); pspDebugScreen sceKernelSleepThread();[I fail @ life]
-
10-12-2006, 11:58 AM #1255AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Pretty sure this should work
EDIT: You never defined printf either, I believe that could cause some problems.Code:#include <pspdebug.h> #include <pspkernel.h> #include <pspdisplay.h> #include <pspctrl.h> #define printf pspDebugScreenPrintf PSP_MODULE_INFO("Counter", 0, 1, 1); /* Exit callback */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { SetupCallbacks(); pspDebugScreenInit(); int counter = 0; int i = 0; SceCtrlData pad; printf("Press [X] To Start the Timer"); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { break; } } while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CIRCLE) { break; } pspDebugScreenClear(); printf("Press [O] To Stop the Timer\n"); printf("Counter: %i", counter); counter++; for(i=0; i<5; i++) { sceDisplayWaitVblankStart(); } } pspDebugScreenClear(); printf("Counter Finished."); printf("Final Count: %i", counter); return 0; }
-
10-12-2006, 12:07 PM #1256QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
The correct version would be
-= Double Post =-Code:for(i=0; i<5; i++) { sceDisplayWaitVblankStart(); } } pspDebugScreenClear(); printf("Coun
PS http://forums.qj.net/f-psp-developme...ml#post1100739Geändert von Lukeson (10-12-2006 um 12:07 PM Uhr) Grund: Automerged Doublepost
-
10-12-2006, 12:12 PM #1257QJ Gamer Blue
- Registriert seit
- Mar 2006
- Ort
- Michigan
- Beiträge
- 211
- Points
- 4.831
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Thanks, homer. That worked perfectly :) I have a feeling I will need to use this thread often now that I am getting started with programming. Thanks for your help.
-
10-12-2006, 12:19 PM #1258AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Don't overuse it though. You learn alot more by trying to solve your problems yourself *wink to Lukeson*
Zitat von Nolimitsdude313
-
10-13-2006, 12:13 AM #1259Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
You're getting your functions mixed up.
Zitat von FreePlay
sceKernelSleepThread() requires no arguments and puts the thread to sleep. sceKernelDelayThread(x) will delay the thread for x amount of microseconds (1000000 microseconds in a second).
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
-
10-13-2006, 12:12 PM #1260QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
http://forums.qj.net/f-psp-developme...ml#post1100739
Sorry again for reposting this, it's just this one-thread-solution sucks so hard, everything that's not on the last page is just lost :?
-= Double Post =-
I commented out lines and found out the PSP freezes due to strcat(recievedMessage, buf); (recieved message has the size 5181 and the strlen 8101 (can somebody tell me why?), for some reason the PSP doesn't freeze whe cat-ing the string, but when exiting the function (=when trying to free recievedMessage?). Does anyone have an idea how to fix this? How would you merge the parts of the string?
-= Double Post =-
Ok, the problem again was that recievedMessage was initialized but not declared... .Geändert von Lukeson (10-13-2006 um 12:12 PM Uhr) Grund: Automerged Doublepost


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