Click here to Skip to main content
15,892,298 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: master file table Pin
«_Superman_»29-Jun-10 15:11
professional«_Superman_»29-Jun-10 15:11 
GeneralRe: master file table Pin
mdocvc30-Jun-10 6:52
mdocvc30-Jun-10 6:52 
AnswerRe: master file table Pin
Member 419459329-Jun-10 16:08
Member 419459329-Jun-10 16:08 
QuestionPass Message to Window Procedure Pin
Fareed Rizkalla29-Jun-10 7:26
Fareed Rizkalla29-Jun-10 7:26 
AnswerRe: Pass Message to Window Procedure Pin
Rajesh R Subramanian29-Jun-10 7:30
professionalRajesh R Subramanian29-Jun-10 7:30 
AnswerRe: Pass Message to Window Procedure Pin
«_Superman_»29-Jun-10 15:16
professional«_Superman_»29-Jun-10 15:16 
Questionwhy segmentation fault ! Pin
wbgxx29-Jun-10 7:07
wbgxx29-Jun-10 7:07 
AnswerRe: why segmentation fault ! Pin
Aescleal29-Jun-10 7:31
Aescleal29-Jun-10 7:31 
Remember what I said about the difference between pointers and arrays earlier? What's probably happening is that the arrays your pointers are pointing to are in a chunk of memory in the program's text section. This section is usually read only - you don't want programs modifying their own code as a rule.

The first strcpy will work okay - you're copying data from the text section to an array on the stack, which is read/write. when you do the second strcpy you're copying from the text section to another bit of the text section and BOOM says the operating system.

If you declare a1 and a2 as:

char a1[] = "hello";
char a2[] = "world";


it'll start working if I'm correct.

Another way of looking at it is...

char a[] = "Hello";


translates to:

- allocate enough memory on the stack to hold 6 characters
- copy "Hello\0" into the memory

while:

char *a = "Hello";


translates to:

- allocate enough memory on the stack to hold a pointer
- initialise the pointer with the address of the constant string "Hello" in the text section

Incidentally this being able to use a char * to point at a const block of characters initialised at compile time is a legacy of the original K&R C which didn't have things like const - it's one of the irritating bits of programming in C. Unfortunately you just have to get used to it.

Hope that helps,

Ash
GeneralRe: why segmentation fault ! Pin
wbgxx29-Jun-10 7:38
wbgxx29-Jun-10 7:38 
GeneralRe: why segmentation fault ! Pin
Aescleal29-Jun-10 8:02
Aescleal29-Jun-10 8:02 
GeneralRe: why segmentation fault ! Pin
David Crow29-Jun-10 9:10
David Crow29-Jun-10 9:10 
GeneralRe: why segmentation fault ! Pin
Aescleal29-Jun-10 9:21
Aescleal29-Jun-10 9:21 
AnswerRe: why segmentation fault ! Pin
Fareed Rizkalla29-Jun-10 7:33
Fareed Rizkalla29-Jun-10 7:33 
AnswerRe: why segmentation fault ! Pin
Hristo-Bojilov29-Jun-10 7:42
Hristo-Bojilov29-Jun-10 7:42 
GeneralRe: why segmentation fault ! Pin
wbgxx29-Jun-10 7:46
wbgxx29-Jun-10 7:46 
GeneralRe: why segmentation fault ! Pin
Aescleal29-Jun-10 8:53
Aescleal29-Jun-10 8:53 
AnswerRe: why segmentation fault ! Pin
Niklas L29-Jun-10 8:37
Niklas L29-Jun-10 8:37 
QuestionSysListView32 help needed Pin
iceeeeman29-Jun-10 7:02
iceeeeman29-Jun-10 7:02 
QuestionRe: SysListView32 help needed Pin
David Crow29-Jun-10 7:16
David Crow29-Jun-10 7:16 
AnswerRe: SysListView32 help needed Pin
iceeeeman29-Jun-10 7:28
iceeeeman29-Jun-10 7:28 
GeneralRe: SysListView32 help needed Pin
Luc Pattyn29-Jun-10 7:50
sitebuilderLuc Pattyn29-Jun-10 7:50 
GeneralRe: SysListView32 help needed Pin
iceeeeman29-Jun-10 7:57
iceeeeman29-Jun-10 7:57 
QuestionRe: SysListView32 help needed Pin
David Crow29-Jun-10 8:02
David Crow29-Jun-10 8:02 
AnswerRe: SysListView32 help needed Pin
iceeeeman29-Jun-10 8:06
iceeeeman29-Jun-10 8:06 
AnswerRe: SysListView32 help needed Pin
Luc Pattyn29-Jun-10 8:12
sitebuilderLuc Pattyn29-Jun-10 8:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.