Mail Archives: djgpp/1997/08/27/14:21:10
Cesar Scarpini Rabak (csrabak AT dce03 DOT ipt DOT br) wrote:
: At 23:35 25/08/97 GMT, firewind wrote:
: [snipped]
: >> myHappy = "Hello, world!";
: > ^^^^^^^^^^^^^^^^^^^^^^^^^^ (3)
: [snipped]
: >3: you're assiging a string to a variable, but this string really has no
: > storage allocated for it.
: >
: This affirmation is incorrect! What this line of code does is to
: _initialize_ the pointer myHappy with the address of the first element of
: the constant array of char _"Hello, world!"_. Nothing particular wrong there.
Actually, he was correct. You cant initialize a pointer to point to
something if you dont allocate memory for it. You CAN say
char* myHappy = "Hello, world!";
but that is different than:
char* myHappy;
myHappy = "Hello, World!";
You will also want to #include <string.h> so you can do a
strcpy(myHappy, "Hello, World!");
after you've allocated the space in myHappy.
Andrew
--
.. . . . . . . . . . . . . . .
. ( Andrew Cheyne / 006809c AT dragon DOT acadiau DOT ca )
o O ( http://dragon.acadiau.ca/~006809c/ )
( .. . . . . . . . .. . . . . )
- Raw text -