Possible Duplicate:
What is the difference between char s[] and char *s in C?
Difference between char *str = “…” and char str[N] = “…”?
I have a structure defined as:
typedef struct
{
bool configured;
bool active;
uint32 lastComms;
uint32 rxChRvdTime;
char *name;
}vehicle;
and I initialize it as follows:
static vehicle *myVehicle;
When I want to initialize the name, I use:
myVehicle->name = "helloworld";
And this works fine. But when I wan't to set it to something other than a string literal, I seem to run into problems.
char *tmpName = "foobar";
strcpy(myVehicle->name, tmpName);
So why doesn't strcpy work? Do I somehow need to preallocate the string size in the structure before hand? Should I not be using a pointer for the 'name' field, since there can only be one vehicle?