123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|650|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> Arch! C strings! (or leader board)

Tue, 30 Aug 2011, 09:35
spinal
This is bugging the hell out of me, when my score is added to my table, it works fine, but when adding the name, if goes nuts and copies it to EVERY entry, not just the one I want

I have never really liked strings in C, but have I done something wrong in the following?



Thanks

-=-=-
Check out my excellent homepage!
Tue, 30 Aug 2011, 09:44
Jayenkai
Ooh, dear.. That's a bad scoreboard!

Step 1. Find new position
newpos=0

for (each score, highest first) {
if myscore>highscore and newpos==0, then newpos=thispos
}

Step 2. If new position, shuffle the rest down a bit.
for (each score, from bottom, backwards to newpos) {
copy Name[here-1] to Name[here]
copy Score[here-1] to Score[here]
}

Step 3. again, only if new position
Name[newpos]=myname
score[newpos]=myscore.


(written in pseudo psycho code, because I usually still manage to stuff it up, somewhere!)


Oh, and your main issue was the "My nice new highscore is bigger than ALL THE OTHER highscores, so each time it would overwrite each one"

Oh, wait no it wasn't.. sorry half-concentrating here.. Watching South Park simultaneously.
Gimme a tick!


rereads over and over...
Yeah, probably a twatty C string thing
Make sure text's big enough to start with. char text[256]; would probably do it, so long as the names aren't ever bigger..

-=-=-
''Load, Next List!''
Tue, 30 Aug 2011, 11:06
HoboBen
I'd suggest using a (fixed-size) linked list. Avoids all that string copying; you should only need to do it once, and would probably be conceptually simpler.

edit: or even just an array of string pointers; copy the pointers, not the string data.

-=-=-
blog | work | code | more code