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 Archaemic So many things wrong with both of those, I don't know where to begin @@ don't nitpick ...
-
08-15-2007, 05:02 PM #6091
don't nitpick i'm trying to get a simple point across not an entire encyclopedia of coding standards.
Zitat von Archaemic
-
08-15-2007, 05:08 PM #6092It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
There's a difference between trying to write code that's clean and code that will compile. That won't even compile. Or if it will, it'll give you a mess of warnings and crash instantly when run.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-15-2007, 05:24 PM #6093
Not nitpicking but i'll just say a couple of things i have noticed from the above posts:
Zitat von califrag
1) As you noted, whether you use a buffer or not depends on if you plan on changing the contents of the string.
- If the string is constant over the entire duration of the program
just use a constant pointer to a string literal.
- If the string changes use a character array and modify the string
with strcpy/sprintf ect.
You could even just have constant string literals and a character pointer that changes which string it points to, it's up to personal preference, there is no wrong or right way.
Keeping things as straight foward as possible like you have is a good idea however :).
2) The string constants in both examples have type 'char', this is incorrect, they should either be a char pointer ('char*' or 'char variable_name[]') or a char array of the appropriate size (char variable_name[size]).
3) You cannot use sprintf to output into a string literal. sprintf is only used to write into a character array defined by the programmer. This is a common mistake, it is important to note that a pointer and an array are not the same thing, the name of an array is a constant pointer but the actual body is a memory space. Before sprintf'ing to a pointer make sure that it points to an array of memory big enough to hold the data.
Hope this helps :)Geändert von psp_jono (08-16-2007 um 06:06 PM Uhr)
-
08-15-2007, 08:01 PM #6094
wow 150 pages into this thread i decide to open my mouth and try to offer some help about a stupid printf function that gerbils can understand. i'm not trying to write code for someone to copy paste into their program and compile immediately.. if i was i'd post the source to hello world. i was simply trying to demonstrate the many different ways that printf can be used WITHOUT sprintf or strcpy or buffers of any kind. the guy I was ORIGINALLY talking to wanted to put static text into his program.. anyways i've learned a lot from this thread.. don't offer any help unless you're just going to copy paste some source code for someone else to copy paste into their program. thanks.
-
08-15-2007, 08:06 PM #6095
??? Sorry to offend, just trying to help mate :)
-
08-15-2007, 08:33 PM #6096
no not you jono you actually kinda backed me up a little thanks, if you notice i made my code more "compileable" for those who are so nitpicky... :)
Zitat von psp_jono
-
08-15-2007, 11:27 PM #6097QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok. im looking for function which would make from string:
hello all
just:
all
basicly, i need to cut away 1st 6 letters? i just cant remeber that function name..... string something[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-16-2007, 01:08 AM #6098Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
I need to know how i would go about doing some animation. Any links ?
-
08-16-2007, 01:39 AM #6099QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
The function you can use is strcpy in the header <string.h>.
Zitat von myschoo
Use it like this -
What that does is copies the data in the string starting at 6 bytes in front of the address of the array until the null byte is reached. It copies it to the beginning of the string.Code:char hello[] = "hello all"; strcpy(hello,hello+6);
You would use the function like this - strcpy(destination,source );
I'll explain a bit more about arrays and whatnot if needed later. for now, I need sleep.[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-16-2007, 01:46 AM #6100Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Ive been googling but still cannot find anything. Is there any source code i can obtain that will show me the basics and i can then build upon ?
-
08-16-2007, 02:44 AM #6101QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
animation? u can use spritesheet and change coordinates using timer or something similar
Moca: sweet thats what i was looking for. thx[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-16-2007, 03:01 AM #6102Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
A timer is the only way ?
-
08-16-2007, 03:02 AM #6103Avada Kedavra

- Registriert seit
- May 2007
- Ort
- Spain
- Beiträge
- 703
- Points
- 6.813
- Level
- 54
- Downloads
- 0
- Uploads
- 0
With OSLib its pretty easy to make animations:)
-
08-16-2007, 06:27 AM #6104Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Is OSLib completed for psp ?
btw thanks for the recommendation im reading up now.
-
08-16-2007, 08:18 AM #6105QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Zitat von myschoo
Would also do the trick.Code:char helloStr[10] = "Hello all"; printf(helloStr); // Hello all helloStr += 6; printf(helloStr); // all
-
08-16-2007, 08:39 AM #6106Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
oslib is the most completed library in existance for the psp :)
Zitat von eldiablov
--------------------------------------------------------------------------------------
-
08-16-2007, 08:47 AM #6107
I'm gonna throw in another one just for fun.
Zitat von _dysfunctional
I am pretty sure that would workCode:char *textall; char texthelloall[] = "Hello All"; textall = strstr(texthelloall,"All");
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-16-2007, 08:51 AM #6108QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
whats the diffrence between:
char *textall; and char textall;[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-16-2007, 09:04 AM #6109It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
One is a pointer and the other one isn't...
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-16-2007, 10:09 AM #6110Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
the first one creates a pointer to a char. the name of the POINTER is textall.
Zitat von myschoo
the second on creates a char. the name of the CHAR is textall.--------------------------------------------------------------------------------------
-
08-16-2007, 10:22 AM #6111QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thx. i think i understand :)
[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-16-2007, 10:45 AM #6112
How would one change the text under the title?
Zitat von myschoo
-
08-16-2007, 11:59 AM #6113QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Wait...you can't do that O_o
Zitat von _dysfunctional
I kinda see what you are tryin' to do but... You can't modify the address of an array o_O. Unless if I missed something huge.[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-16-2007, 12:17 PM #6114QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
not possible anymore.
Zitat von Mr305
before, premium member could pay it for non-prem.[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-16-2007, 02:03 PM #6115QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Your right, your right.
Zitat von Moca
It would work as a pointer, but not as a plain array. My mistake.
-
08-16-2007, 04:33 PM #6116
Would have worked with the use of another pointer,Code:char helloStr[10] = "Hello all"; printf(helloStr); // Hello all helloStr += 6; printf(helloStr); // all
or without pointer arithmetic,Code:char helloStr[10] = "Hello all"; printf(helloStr); // Hello all char* allStr = helloStr; allStr += 6; printf(allStr); // all
or without storing a pointer at all,Code:char helloStr[10] = "Hello all"; printf(helloStr); // Hello all char* allStr = &helloStr[6]; printf(allStr); // all
Code:char helloStr[10] = "Hello all"; printf(helloStr); // Hello all printf(&helloStr[6]); // all
Geändert von psp_jono (08-16-2007 um 05:44 PM Uhr)
-
08-16-2007, 04:47 PM #6117QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 172
- Points
- 3.680
- Level
- 38
- Downloads
- 0
- Uploads
- 0
jono wouldn't the last example only display the 6th character not up to the 6th character?
-
08-16-2007, 05:15 PM #6118It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I'm fairly certain jono is right on all points in that post.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-16-2007, 05:44 PM #6119
It would print the 6th character and every character following until a null ('\0') character is encountered :).
Zitat von seenit
Heres another one:
I'm not a big fan of pointer arithmetic most of the time, it can make code a fair bit harder to understand. Although at times it does make sense to use it.Code:char helloStr[10] = "Hello all"; printf( helloStr); // prints "Hello all" printf( helloStr + 6); // prints "all"
EDIT: null character was '\n' rather than '\0'. oops :o.
-
08-16-2007, 05:46 PM #6120It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Ehh, not quite right on all points this time, jono. \n is the newline character. \0 is the null character.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ


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