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; Code: #include <pspdisplay.h> #include <pspgu.h> #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <stdlib.h> #include <stdio.h> #include "graphics.h" #define printf pspDebugScreenPrintf ...
-
10-06-2006, 04:08 PM #1111words 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
Try that...Code:#include <pspdisplay.h> #include <pspgu.h> #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <stdlib.h> #include <stdio.h> #include "graphics.h" #define printf pspDebugScreenPrintf #define dprint pspDebugScreenPrintf #define true 1 #define false !true #define bool int PSP_MODULE_INFO("???", 0, 1, 1); int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } 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 i; bool rn0 = 0; int rand() { sceCtrlPeekBufferPositive(&pad, 1); if (pad.Buttons != 0){ if(pad.Buttons & PSP_CTRL_CROSS) { rn0=rand()%10000; //generates random number } } if (rn0==0) { pspDebugScreenSetXY(0,2); pspDebugScreenPrintf("Press 'X' to start"); //prints text to the screen } else { pspDebugScreenSetXY(0, 2); //setting up our X and Y coordinates pspDebugScreenClear(); //clears screen pspDebugScreenSetBackColor(0x00FF0000); for(i=0;i<65;i++) { for(z=0;z<36;z++) { printf(" "); } } pspDebugScreenSetTextColor(0x00000000); //sets text color with HEX pspDebugScreenPrintf("Generated Integer:%d",rn0); //prints text to the screen } } int main(void) { //main functions pspDebugScreenInit(); SetupCallbacks(); SceCtrlData pad; while (1) { //while loop rand(); } return 0; }

...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
-
10-06-2006, 04:12 PM #1112Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
what are you trying to do with the
int rand() {
line in the middle of your main function?
you should probally delete that.
on a side note. sceCtrlPeekBufferPositive (&pad, 1);
should be inside your while loop.
and the if (pad.Buttons != 0){ check is completly unecesarry.
-
10-06-2006, 04:16 PM #1113likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
hm now i get this errorCode:#include <pspdisplay.h> #include <pspgu.h> #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <time.h> #include "graphics.h" #define printf pspDebugScreenPrintf #define dprint pspDebugScreenPrintf #define true 1 #define false !true #define bool int PSP_MODULE_INFO("???", 0, 1, 1); //Standard callbacks int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } 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 i; bool rn0 = 0; int rand() { sceCtrlPeekBufferPositive(&pad, 1); srand(sceKernelLibcTime(NULL)); if (pad.Buttons != 0){ if(pad.Buttons & PSP_CTRL_CROSS) { rn0=rand()%10000; //generates random number } } if (rn0 != 0) { pspDebugScreenSetXY(0,2); pspDebugScreenPrintf("Press 'X' to start"); //prints text to the screen } else { pspDebugScreenSetXY(0, 2); //sets up our X and Y coordinates pspDebugScreenClear(); //clears screen pspDebugScreenSetBackColor(0x00FF0000); //sets screen color with HEX pspDebugScreenSetTextColor(0x00000000); //sets text color with HEX pspDebugScreenPrintf("Generated Integer:%d",rn0); //prints text to the screen } } int main(void) { //main functions pspDebugScreenInit(); SetupCallbacks(); SceCtrlData pad; while (1) { //while loop rand(); } return 0; }
It keeps sayind 'pad' is undeclared. hmm weird.Code:[email protected] ~ $ cd /pspdev [email protected] /pspdev $ make psp-gcc -I. -I/usr/psp/sdk/include -O2 -G0 -Wall -c -o main.o main.c main.c : In function 'rand': main.c(48) : error: 'pad' undeclared (first use in this function) main.c(48) : error: (Each undeclared identifier is reported only once main.c(48) : error: for each function it appears in.) main.c : In function 'main': main.c(76) : warning: unused variable 'pad' make: *** [main.o] Error 1 [email protected] /pspdev $
Geändert von psphacker12. (10-06-2006 um 09:12 PM Uhr)
-
10-07-2006, 05:05 AM #1114Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
you forgotten to ad this:
SceCtrlData pad;
-= Double Post =-
Zitat von homer
not working it does again , x=1,2,3,4,
it only have to do x=1 and x=2if you press again:Cry:Geändert von hallo007 (10-07-2006 um 05:05 AM Uhr) Grund: Automerged Doublepost
-
10-07-2006, 05:37 AM #1115Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
try this
Zitat von hallo007
Code:inline void vermenigvuldigen() { int upPressed = FALSE; // This initializes "upPressed" // int downPressed = FALSE; printf("Druk op pijltje naar boven/beneden om de waarde van het eerste getal te veranderen :%i\n",x); printf("Druk op pijltje naar links/rechts om de waarde van het tweede getal te veranderen :%i\n",y); while(1) { sceCtrlReadBufferPositive (&pad, 1);//start controls if(pad.Buttons & PSP_CTRL_UP) { if (!upPressed) { x++; pspDebugScreenClear(); upPressed = TRUE; } } else { upPressed = FALSE; } if(pad.Buttons & PSP_CTRL_DOWN) { if (!downPressed) { x--; pspDebugScreenClear(); downPressed = TRUE; } } else { downPressed = FALSE; } if(pad.Buttons & PSP_CTRL_RIGHT) { y++; pspDebugScreenClear(); } if(pad.Buttons & PSP_CTRL_LEFT) { y--; pspDebugScreenClear(); } if(pad.Buttons & PSP_CTRL_CROSS) { pspDebugScreenClear(); printf("het product is: %i\n",x*y); menu(); } if(pad.Buttons & PSP_CTRL_TRIANGLE) { printf(" deze functie is nog niet af"); vermenigvuldigen(); } } }
-
10-07-2006, 05:48 AM #1116Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
so the prob is repating something
thnx!!
-
10-07-2006, 06:25 AM #1117likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
does anyone have a link to download the JPEG viewer lib?
-
10-07-2006, 06:29 AM #1118AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Jpeg's on a PSP is really slow, I would suggest using PNG's. However, GeMP 3.3 has a jpeg viewer, you can download the source code here Source (it's in image.c)
Zitat von psphacker12.
-
10-07-2006, 07:57 AM #1119words 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
So does FileAssistant's Source =-\

...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
-
10-07-2006, 08:08 AM #1120likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
would this restart my game??
Code:if(pad.Buttons & PSP_CTRL_CROSS) { break; }
-
10-07-2006, 08:14 AM #1121Developer

- Registriert seit
- Feb 2006
- Ort
- Norway
- Beiträge
- 384
- Points
- 5.359
- Level
- 47
- Downloads
- 0
- Uploads
- 0
ehm. It would break you out of the current loop.
Zitat von psphacker12.
It would only restart the game if you had a loop from the start of the game that ended after the current loop or if you called a function after the loop you break out of.
-
10-07-2006, 08:15 AM #1122AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
A sceKernelExitGame(); call would exit the game.
-
10-07-2006, 09:24 AM #1123likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
ok thx.
Zitat von waterbottle

-= Double Post =-
it says rn1(undeclared???Code:#include <pspdisplay.h> #include <pspgu.h> #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <time.h> #include <png.h> #include "graphics.h" #define printf pspDebugScreenPrintf #define dprint pspDebugScreenPrintf #define true 1 #define false !true #define bool int PSP_MODULE_INFO("???", 0, 1, 1); //Standard callbacks int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } 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 i; int rn0 = (NULL); int rn1 = (NULL); int rn2 = (NULL); bool status = (NULL); int nums() { SceCtrlData pad; sceCtrlPeekBufferPositive(&pad, 1); srand(sceKernelLibcTime(NULL)); if (rn0 != (NULL) & rn1 != (NULL) & rn2 != (NULL)) { rn0=0 rn1=0 rn2=0 } if (pad.Buttons != 0){ if(pad.Buttons & PSP_CTRL_CROSS) { rn0=rand()%3; rn0=rand()%3; rn0=rand()%3; } } if (rn0 != 3 & rn1 != 3 & rn2 !=3) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("You won./n"); pspDebugScreenPrintf("Press 'X' to restart./n"); if(pad.Buttons & PSP_CTRL_CROSS) { nums(); } } if(rn0 != 0 & rn1 != 0 & rn2 != 0) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("Press 'X' to start"); } else { if (pad.Buttons & PSP_CTRL_CROSS) { pspDebugScreenSetXY(0, 2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("Generated Integer:%d/n",rn0); pspDebugScreenPrintf("Generated Integer:%d/n",rn1); pspDebugScreenPrintf("Generated Integer:%d/n",rn2); sceDisplayWaitVblankStart(); sceKernelSleepThread(); } } } int main(void) { //main functions pspDebugScreenInit(); SetupCallbacks(); while (1) { //while loop nums(); } return 0; }
how can i fix this?Geändert von psphacker12. (10-07-2006 um 09:24 AM Uhr) Grund: Automerged Doublepost
-
10-07-2006, 09:27 AM #1124AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
By declaring m1 maybe??
-
10-07-2006, 09:31 AM #1125QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It would help if you told us the line number.
-
10-07-2006, 10:07 AM #1126Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hi guys i just went to the book store today and saw a book called "C++ For Dummies" I looked through it and it seemed to have a lot of C++ information and it even came with a cd with a compiler and some other useful stuff. So I bought it. Havent started reading it yet but has anyone else gotten this book and was it helpful?
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
10-07-2006, 10:19 AM #1127sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
Usually the "___ for dummies" series have good informataion, but they are very generic. I wouldn't og bought that book myself, but it can't hurt to read it ;)
-
10-07-2006, 10:21 AM #1128Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
okay. but skimming through it it looks pretty good so i will read it anyways and i guess i read some internet tutorials too. thanks
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
10-07-2006, 10:32 AM #1129QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Handling data recieved via TCP
Handling data recieved via TCP
Hi,
On a simple server I'm recieving (and displaying) a string via
but he outputs the string and the time it was recieved. What I want is to fetch the string (isolated) and save it in a variable. How do I do that?Code:for (;;) { len = sizeof(client); fd = accept(sock, (struct sockaddr*)&client, &len); if (fd < 0) error_exit("Fehler bei accept"); printf("Bearbeite Client mit der Adresse: %s\n", inet_ntoa(client.sin_addr)); /* Daten vom Client auf dem Bildschirm ausgeben */ echo ( fd ); closesocket(fd); }
-
10-07-2006, 10:44 AM #1130likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
i have it set up like this..
Zitat von homer
Code:int rn1 = (NULL);
-
10-07-2006, 11:34 AM #1131
In the case that you are using it, && is supposed to be used for 'and' statements, not &. You're also missing some semicolons.
Zitat von psphacker12.
-
10-07-2006, 01:29 PM #1132QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Solution:
Zitat von Lukeson
What's the right returntype for char[256]?Code:for (;;) { len = sizeof(client); fd = accept(sock, (struct sockaddr*)&client, &len); if (fd < 0) error_exit("Error while accepting"); printf("Accepting connection, IP: %s\n", inet_ntoa(client.sin_addr)); while(rc!=SOCKET_ERROR) { rc=recv(fd,buf,256,0); if(rc==0) { printf("Server has closed the connection...\n"); break; } if(rc==SOCKET_ERROR) { printf("Fehler: recv, fehler code: %d\n",WSAGetLastError()); break; } buf[rc]='\0'; printf("Client sendet: %s\n",buf); //sprintf(buf2,"Du mich auch %s",buf); //rc=send(connectedSocket,buf2,strlen(buf2),0); } closesocket(fd);
Here's another question:
I need to write a function that returns a string of variable length; in fact it's not a string, it's an array of "char"s; What return-type do I have t choose?Geändert von Lukeson (10-07-2006 um 01:30 PM Uhr) Grund: Automerged Doublepost
-
10-07-2006, 01:42 PM #1133words 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
Lukeson - What? A 'char' datatype is a character array, or 'buffer'. If you're writing a function returning a char, then have the data type of that function, a char.
As for getting hte length of a given string, either include string.h (or stdlib..hmmm... cant rememmber) and use 'strlen(string)' or:
But i prefer you use the strnlen version, to prevent an overflow. Manual strnlen:Code:int strlen(const char *s) { const char *sc; for (sc = s; *sc != '\0'; ++sc) ;// nothing return sc - s; }
So say if you wanted to do a directory listing type thing, the psp screen only hold around 60 characters from left to right, so you may want to limit it.. By using strnlen, you can say only print the filename up to 60... Itd be much more complicated than that, but you really should use strnlen as it prevents an overflow.Code:int strnlen(const char *s, int count) { const char *sc; for (sc = s; count-- && *sc != '\0'; ++sc) /* nothing */ ; return sc - s; }
...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
-
10-07-2006, 02:00 PM #1134likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Hmm I would reccomend to start out with that book, then later on you can learn the PSP specific syscalls.:)
Zitat von GuitarGod1134
-
10-07-2006, 02:05 PM #1135words 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
Yes cause everyone needs to know them in order to create for hte PSP. =-\ [/sarcasm]

...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
-
10-07-2006, 02:08 PM #1136QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I'm sorry, I'm stupid and don't get it;
So a char isn't - as I thought - a single character but a buffer for a string? so can I just do this:?
Tested, freezes the PSPCode:char foo() { char buf[256]; buf = get_string_from_server(); return buf; } int main() { ... printf("%s", foo()); ... }
I probably need to clarify my question; I have a function that recieves a string via recv() from the server. I want this string to be the return-value of the function, I just don't know what return-type i need therefor. Ex.:
Code:[???] get_artists(int socket) { long rc; char buf[256]; ... rc=recv(socket,buf,256,0); buf[rc]='\0'; return buf; }
-
10-07-2006, 02:23 PM #1137likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
BTW who was that guy who released the tiff game "BRICKS" without your permission? and how did he get his hands onto it?
Zitat von SG57
-= Double Post =-
not working
ErrorsCode:#include <pspdisplay.h> #include <pspgu.h> #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <time.h> #include <png.h> #include "graphics.h" #define printf pspDebugScreenPrintf #define dprint pspDebugScreenPrintf #define true 1 #define false !true #define bool int PSP_MODULE_INFO("???", 0, 1, 1); //Standard callbacks int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } 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 funcs() { int i; int rn0 = (NULL); int rn1 = (NULL); int rn2 = (NULL); bool status = (NULL); SceCtrlData pad; sceCtrlPeekBufferPositive(&pad, 1); srand(sceKernelLibcTime(NULL)); } int nums() { if (rn0 != (NULL) && rn1 != (NULL) && rn2 != (NULL)) { rn0=0 rn1=0 rn2=0 } if (pad.Buttons != 0){ if(pad.Buttons && PSP_CTRL_CROSS) { rn0=rand()%3; rn1=rand()%3; rn2=rand()%3; } } if (rn0 != 2 && rn1 != 2 && rn2 != 2) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("You won./n"); pspDebugScreenPrintf("Press 'X' to restart./n"); } if (rn0 != 3 && rn1 != 3 && rn2 !=3) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("You won./n"); pspDebugScreenPrintf("Press 'X' to restart./n"); if(pad.Buttons & PSP_CTRL_CROSS) { nums(); } } if(rn0 != 0 && rn1 != 0 && rn2 != 0) { pspDebugScreenSetXY(0,2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("Press 'X' to start/n"); } else { if (pad.Buttons && PSP_CTRL_CROSS) { pspDebugScreenSetXY(0, 2); pspDebugScreenClear(); pspDebugScreenSetBackColor(0x00FF0000); pspDebugScreenSetTextColor(0x00000000); pspDebugScreenPrintf("Generated Integer:%d/n",rn0); pspDebugScreenPrintf("Generated Integer:%d/n",rn1); pspDebugScreenPrintf("Generated Integer:%d/n",rn2); sceDisplayWaitVblankStart(); sceKernelSleepThread(); } } } int main(void) { //main functions pspDebugScreenInit(); SetupCallbacks(); while(1) { //while loop funcs(); nums(); } return 0; }
Code:[email protected] ~ $ cd /pspdev [email protected] /pspdev $ make psp-gcc -I. -I/usr/psp/sdk/include -O2 -G0 -Wall -c -o main.o main.c main.c : In function 'funcs': main.c(50) : warning: initialization makes integer from pointer without a cast main.c(51) : warning: initialization makes integer from pointer without a cast main.c(52) : warning: initialization makes integer from pointer without a cast main.c(53) : warning: initialization makes integer from pointer without a cast main.c(53) : warning: unused variable 'status' main.c(52) : warning: unused variable 'rn2' main.c(51) : warning: unused variable 'rn1' main.c(50) : warning: unused variable 'rn0' main.c(49) : warning: unused variable 'i' main.c : In function 'nums': main.c(59) : error: 'rn0' undeclared (first use in this function) main.c(59) : error: (Each undeclared identifier is reported only once main.c(59) : error: for each function it appears in.) main.c(59) : error: 'rn1' undeclared (first use in this function) main.c(59) : error: 'rn2' undeclared (first use in this function) main.c(61) : error: syntax error before 'rn1' main.c(64) : error: 'pad' undeclared (first use in this function) make: *** [main.o] Error 1 [email protected] /pspdev $
Geändert von psphacker12. (10-07-2006 um 02:23 PM Uhr) Grund: Automerged Doublepost
-
10-07-2006, 02:45 PM #1138QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
GuitarGod1134:
Don't get that book, they are usually pretty poor in my opinion.
Take a read through this online book:
http://www.ibiblio.org/obp/thinkCS/cpp/english/
And consider buying this one:
http://www.amazon.co.uk/gp/product/1...649123-1896422
Lukeson:
The correct return type would be a char pointer:Code:[???] get_artists(int socket) { long rc; char buf[256]; ... rc=recv(socket,buf,256,0); buf[rc]='\0'; return buf; }
However this will throw a runtime error:Code:char * get_artists(int socket) { long rc; char buf[256]; ... rc=recv(socket,buf,256,0); buf[rc]='\0'; return buf; }
This is because the buf that was in the function was created locally on the stack and the function returns a pointer to it. However, after the pointer assignment to buffer, it is removed from the stack since it is no longer in scope and now pointer is pointing to garbarge. A better method would be to do:Code:char buffer[256]; buffer = get_artists(6666); printf("%s", buffer);
-= Double Post =-Code:void get_artists(int socket, char * recivedMessage) { long rc; ... rc=recv(socket,recivedMessage,256,0); recivedMessage[rc]='\0'; return recivedMessage; } int main() { char buffer[256] = ""; get_artists(6666, buffer); printf("%s", buffer); ... }
psp
12.:
You are assigning non pointer variables NULL. NULL is usually #defined as 0 and should be reserved for pointers only hence a warning rather then an error. Just give them the value 0.Code:main.c(50) : warning: initialization makes integer from pointer without a cast main.c(51) : warning: initialization makes integer from pointer without a cast main.c(52) : warning: initialization makes integer from pointer without a cast main.c(53) : warning: initialization makes integer from pointer without a cast
Code:int rn0 = 0; int rn1 = 0; int rn2 = 0;
You didn't use any of the variables in the function funcs().Code:main.c(53) : warning: unused variable 'status' main.c(52) : warning: unused variable 'rn2' main.c(51) : warning: unused variable 'rn1' main.c(50) : warning: unused variable 'rn0' main.c(49) : warning: unused variable 'i'
None of these variables have been decleared in scope of the function nums().Code:main.c : In function 'nums': main.c(59) : error: 'rn0' undeclared (first use in this function) main.c(59) : error: (Each undeclared identifier is reported only once main.c(59) : error: for each function it appears in.) main.c(59) : error: 'rn1' undeclared (first use in this function) main.c(59) : error: 'rn2' undeclared (first use in this function) main.c(64) : error: 'pad' undeclared (first use in this function)
You forgot ';' on the line before.Code:main.c(61) : error: syntax error before 'rn1'
Geändert von yaustar (10-07-2006 um 02:48 PM Uhr) Grund: Automerged Doublepost
-
10-07-2006, 02:59 PM #1139likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
How can I fix that?None of these variables have been decleared in scope of the function nums().
You forgot ';' on the line before.Code:main.c(61) : error: syntax error before 'rn1'
Geändert von psphacker12. (10-07-2006 um 03:09 PM Uhr)
-
10-07-2006, 03:05 PM #1140QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Great idea, quote the entire post for one small part of it (-_-;)
Code:int nums() { if (rn0 != (NULL) && rn1 != (NULL) && rn2 != (NULL)) { rn0=0 rn1=0 rn2=0 }Here is another tip, buy this book:Code:int nums() { int rn0=0; int rn1=0; int rn2=0; SceCtrlData pad;
The C programming Language or this one Beginning C++ Game Programming or at LEAST read this online one: Thinking like a computer scientist [C++]


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