Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple Character Array Crap

Started by neonfaktory Oct 18, 2003 at 11:01 AM 2 replies 750+ views
Original Post
neonfaktory
neonfaktory
Real simple: I'm creating my High Score List in C++. Upon Initialization it Loads the High Score data, and if it doesn't exist yet, it fills the array with the default data. At the end it dumps the updated list back into the file, thus creating a default score list upon leaving the game the first time. All I'm trying to do is make the character array of my SCORE struct = a name. Code :
struct SCORE{char name[9]; Uin32 score;}
SCORE gHISCORE[10];
...
// If File Doesn't Exist Yet, Fill List with Default
gHISCORE[ i ].name = "Beatme";
...  
I was hoping it would be this simple, but first it gives me errors about not being able to convert the char array lengths, and when I do match up the lengths via "Beatme " it gives me another error about "left operand must be l-value". GAH, I always hated character array handling, but I suppose I should finally clear up my problems with it. Thanks for any help. [edit]Added spaces to '[ i ]', board thought I wanted italics[/edit] [edited by - neonfaktory on October 18, 2003 12:03:57 PM]
weee!
Lunatic Raven
Lunatic Raven
You can''t reassign character arrays like that. In order to do what you want you need to use the function strcpy().

An example:

strcpy(gHISCORE[ i ].name, "Beatme");


You need to include the header string.h to use the function.
"...."
neonfaktory
neonfaktory
Ah, thanks for the response.

It didn't give me any errors when using strncpy on the character array, but for some reason it won't let me change the character array member of my struct into a string - gives me a bunch of errors. I've tried declaraing it multiple ways, with dimensions, without, initializing it on declaration, etc. They all break. Thanks again for any additional help.

[edited by - neonfaktory on October 18, 2003 7:41:58 PM]
weee!
George2
George2
use std::string , much better :


#include <string>

using namespace std;

string foo;

foo = "bar"; // This works with std::string


"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.