Why can''t I use just a array of chars to the player name? No one has a 300 charachter name!
Thanks, Arthur(rockslave)
strings...damn them
Well, rockslave, you CAN just use an array of chars. However, you can never say "no one has a 300 character name". The things that users will do to a program are amazing. If there is a strange case that will break your program, someone is bound to find it. Some lunatic will want to call himself "Thrackerzog the supreme ultimate amazing awesome master of the universe with gigantic armpits... " etc. So, what you need to do is make sure that the user can''t enter something so long that it bleeds over into the memory out of bounds of your array.
Hey, Jaxson, but I can limit the amount of charachters, cannot I? None of the games I know let you be named "Thrackerzog the supreme ultimate amazing awesome master of the universe with gigantic armpits", and it''s very bad for dialogues! And there is no good name with such tons of chars!
Thanks, Arthur(rockslave)
Thanks, Arthur(rockslave)
import money.*;#include "cas.h"uses bucks;
Now what''s up with this?:
char something[50];
something = "Strings";
Complier Error:
cannot convert from ''char [7]'' to ''char [50]''
There is no context in which this conversion is possible
char something[50];
something = "Strings";
Complier Error:
cannot convert from ''char [7]'' to ''char [50]''
There is no context in which this conversion is possible
I believe something is not an lvalue. An lvalue is a container for data and can be on the left hand side of an assignment statement. something evaluates to a pointer at compile time which points to the array of 50 bytes.
I don''t believe something is a container or variable if you will.
However something[0] or something[16] is a variable.
Now it is OK to do this;
char something[50] = "Strings";
I don''t believe something is a container or variable if you will.
However something[0] or something[16] is a variable.
Now it is OK to do this;
char something[50] = "Strings";
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
quote:
Now it is OK to do this;
char something[50] = "Strings";
Really? I thought that would get the same lvalue error.
I''ve always been under the impression that you would have to do:
char something[50];strcpy(something,"Strings");
Are you sure you can initialize a string with an ''='' operator?
"Death to all who oppose me."
- The Goblin (madgob@aol.com)
Yep. I''m positive.
And I think it is a special case handled by the compiler because ordinarily a quoted string like "Strings" evaluates to a pointer at compile-time. In other words, it is only legal in a declaration statemnet.
And I think it is a special case handled by the compiler because ordinarily a quoted string like "Strings" evaluates to a pointer at compile-time. In other words, it is only legal in a declaration statemnet.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Hey, bishop_pass, I feel I gotta disagree. It changes from compiler to compiler. Borland, for instance, wants you to use functions from string.h .
Thanks, Arthur(rockslave)
Thanks, Arthur(rockslave)
import money.*;#include "cas.h"uses bucks;
I agree with the strcpy() function but now...
Let''s say you have a class:
class Test
{
private:
char myString[50];
public:
//accessor
char GetmyString();
};
char Test::GetmyString()
{
return (myString);
}
It won''t work, how could you return a string?
Let''s say you have a class:
class Test
{
private:
char myString[50];
public:
//accessor
char GetmyString();
};
char Test::GetmyString()
{
return (myString);
}
It won''t work, how could you return a string?
rockslave, maybe it is a compiler issue and maybe there is an option to allow it or disallow it.
I am not sure what ANSI C says about that. Are you positive you are compiling with ANSI C and don''t have a flag turned on or off?
And besides, maybe it is irrelevant if you are using C++.
Anyway, if you want to try it and it works, great. If not, then that''s OK too.
I am not sure what ANSI C says about that. Are you positive you are compiling with ANSI C and don''t have a flag turned on or off?
And besides, maybe it is irrelevant if you are using C++.
Anyway, if you want to try it and it works, great. If not, then that''s OK too.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement