Re: What is wrong with this code?
From: John Carson (donaldquixote_at_datafast.net.au)
Date: 03/24/04
- Next message: Robert M.: "Re: What is wrong with this code?"
- Previous message: Robert M.: "What is wrong with this code?"
- In reply to: Robert M.: "What is wrong with this code?"
- Next in thread: Robert M.: "Re: What is wrong with this code?"
- Reply: Robert M.: "Re: What is wrong with this code?"
- Reply: Robert M.: "Re: What is wrong with this code?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Mar 2004 18:45:24 +1100
"Robert M." <rmilh@hotmail.com> wrote in message
news:ewxOb8WEEHA.3016@TK2MSFTNGP11.phx.gbl
> #include <string.h>
>
> int main(int argc, char* argv[])
> {
> const char* src[] = {"string"};
> char* dst[] = {"xxxxxx"};
>
> strcpy(dst[0], src[0]); //Access violation here !!!!
>
> return 0;
> }
dst is an array of pointers to char. You are assigning a string literal,
"xxxxxx" to the first element of that array. String literals are "read-only"
regardless of whether you assign them to a char * pointer or a const char *
pointer. You cannot change the contents of the memory that stores string
literals.
-- John Carson 1. To reply to email address, remove donald 2. Don't reply to email address (post here instead)
- Next message: Robert M.: "Re: What is wrong with this code?"
- Previous message: Robert M.: "What is wrong with this code?"
- In reply to: Robert M.: "What is wrong with this code?"
- Next in thread: Robert M.: "Re: What is wrong with this code?"
- Reply: Robert M.: "Re: What is wrong with this code?"
- Reply: Robert M.: "Re: What is wrong with this code?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|