Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


I hate char arrays >_<

This topic is 5417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok ive got something like this. void setName(char Name) {itsName = Name;}; and I get this error c:\my documents\c++ programs\mybattle\main.cpp(166) : error C2664: 'setName' : cannot convert parameter 1 from 'char [8]' to 'char' This conversion requires a reinterpret_cast, a C-style cast or function-style cast I beleave it has something to do with how you declair the char arrays or what not but my book is not helping at all. Please help, thanks (gawd this has gota be my millionth question ) [edited by - Dko on January 24, 2004 5:26:42 PM]

Share this post

Link to post
Share on other sites
You''re also going to have to treat them as dynamic arrays since you don''t know how big the person''s name is. I''m still trying to figure this out myself, but look up calloc and realloc in your book or online. Those should be what you''re looking for to set the array up to be the right length whenever you need to change the name.

Share this post

Link to post
Share on other sites

You might want to look at the string class in the std namespace, it can help with general string options a lot.

you can declare like this

std::string Name = "Freak";

or if you have using namespace std; before it than you can just call string Name = "Freak";

that way you are not using and memory copy functions and all that stuff that is really a pain...

Wait until you need to convert char arrays to unicode, then you will get nose bleeds.

if you are using char though then here a few handy hints.

You cna declare like this,

char * Name = "jack";
char Name[]="jack";

look up functions like strcpy, strcat, itoa and so forth.

good luck

Share this post

Link to post
Share on other sites
Still can''t figure it out. Here''s my character.h and the line that generates the error in main.cpp

#include <iostream>
#include <stdlib.h>

using namespace std;

class Creature
void setName(char Name) {itsName = Name;};
void setHp(int Hp) {
itsHp = Hp;
MaxHp = itsHp;
void changeHp(int Hp) {itsHp = Hp;};
void setAtk(int Atk) {itsAtk = Atk;};
void setDef(int Def) {itsDef = Def;};
void setSpd(float Spd) {itsSpd = Spd;};
void setATB(float ATB) {itsATB = ATB;};

int CalculateATB() {
this->setATB(this->itsATB + (96 * (this->showSpd() + 20)) / 16); // My riped off ff3/6 formule :P

if (this->itsATB >= 65535)
return 1;
return 0;
int EnterName() {
cout << "Please enter your characters name\n";
char nameTemp ;
cin >> nameTemp;
char showName() {return itsName;};
int showHp() {return itsHp;};
int showMaxHp() {return MaxHp;};
int showAtk() {return itsAtk;};
int showDef() {return itsDef;};
float showSpd() {return itsSpd;};
int showATB() {
float NumOfBars = 10;
float interval = 65535 / NumOfBars;
float bars = itsATB / interval;
cout << "(";
for(int i = 0; i < bars; i++)
cout << "|";
for(float j = bars; j <= NumOfBars; j++)
cout << "-";
cout << ")";
return 0;


char itsName;
int itsHp;
int MaxHp;
int itsAtk;
int itsDef;
float itsSpd;
float itsATB;


Share this post

Link to post
Share on other sites
The char type is just one character. To have more than one character (strings) you''d need to use char* like ch1pz mentioned

Ryan Bujnowicz
[ vangelis ]

Share this post

Link to post
Share on other sites
Ok now the prob I get is this warrning
c:\my documents\c++ programs\mybattle\character.h(30) : warning C4700: local variable ''nameTemp'' used without having been initialized

and the program crashes when ever I enter a name

Share this post

Link to post
Share on other sites
void SetName(char * newName)
int len;
len = strlen(newName);
delete [] name;
name = new char[len];

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!