Advertisement

strings...damn them

Started by July 05, 2000 03:18 PM
34 comments, last by Joker2000 24 years, 5 months ago
By the way, this is perfectly legal in any C variation:

char something[50] = { ''S'', ''t'', ''r'', ''i'', ''n'', ''g'', ''s'' };

_______________________________
"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.
vbisme, the reason your code doesn''t work is because myString isn''t a char, it''s a char*. Therefore if you change your GetmyString() to this:
    char* Test::GetmyString(){    return (myString);}    


it will work.
Advertisement
Ha!

I just consulted a book on valid C syntax.
This is legal. If it doesn''t work, then your compiler sucks because it doesn''t recognize valid syntax.

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.
if...:
class Test
{
private:
char myString;

char *Test::GetmyString()
{
return (mySring);
}

Compiler Error: cannot convert from ''char[50]'' to ''char[]''
vbisme,

What compiler are you using? What are the settings?

Try this:

    class Test{private:    char myString;    char* Test::GetmyString()    {        return (char*)(mySring);    }};    

Although I''m not quite sure why it''s giving that error.
When working with strings, strcpy is the way to go...

/CMN

This topic is closed to new replies.

Advertisement