Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
Richard MacCutchan11-Oct-09 22:40
mveRichard MacCutchan11-Oct-09 22:40 
GeneralRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
theCPkid11-Oct-09 22:59
theCPkid11-Oct-09 22:59 
GeneralRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
Richard MacCutchan11-Oct-09 23:40
mveRichard MacCutchan11-Oct-09 23:40 
AnswerRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
carter200011-Oct-09 18:31
carter200011-Oct-09 18:31 
GeneralRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
Richard MacCutchan11-Oct-09 22:42
mveRichard MacCutchan11-Oct-09 22:42 
GeneralRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
carter200011-Oct-09 23:09
carter200011-Oct-09 23:09 
AnswerRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
Richard MacCutchan11-Oct-09 23:45
mveRichard MacCutchan11-Oct-09 23:45 
AnswerRe: I want to copy strings,but occur this....."Access to memory errors....",why? [modified] Pin
Richard MacCutchan11-Oct-09 22:39
mveRichard MacCutchan11-Oct-09 22:39 
I think the problem is probably in the following statement: while((*to++ = *from++) != '\0');. The C++ language specification for the assignment operator states "The assignment operators return the value of the object specified by the left operand after the assignment." i.e the to pointer. Thus in the above statement the comparison is done with the next element of the to array, which being longer than the from array, contains the character 'o'. The while loop is now out of control as it is copying garbage. Rework your loop so that it tests the source array element for '\0', rather than the destination.

[EDIT]Sorry, I got this wrong, the result of the expression is to before it gets incremented, hence it is correct.[/EDIT]

modified on Monday, October 12, 2009 5:45 AM

AnswerRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
Iain Clarke, Warrior Programmer11-Oct-09 23:27
Iain Clarke, Warrior Programmer11-Oct-09 23:27 
AnswerRe: I want to copy strings,but occur this....."Access to memory errors....",why? Pin
rejupal12-Oct-09 20:10
rejupal12-Oct-09 20:10 
QuestionIPropertyUI::ParsePropertyName return always E_FAIL Pin
Emulator ®11-Oct-09 16:02
Emulator ®11-Oct-09 16:02 
AnswerRe: IPropertyUI::ParsePropertyName return always E_FAIL Pin
«_Superman_»11-Oct-09 16:06
professional«_Superman_»11-Oct-09 16:06 
GeneralRe: IPropertyUI::ParsePropertyName return always E_FAIL Pin
Emulator ®11-Oct-09 16:10
Emulator ®11-Oct-09 16:10 
GeneralRe: IPropertyUI::ParsePropertyName return always E_FAIL Pin
Emulator ®11-Oct-09 16:23
Emulator ®11-Oct-09 16:23 
GeneralRe: IPropertyUI::ParsePropertyName return always E_FAIL Pin
Emulator ®11-Oct-09 23:17
Emulator ®11-Oct-09 23:17 
QuestionOnPaint Notification question Pin
ForNow11-Oct-09 14:52
ForNow11-Oct-09 14:52 
AnswerRe: OnPaint Notification question Pin
«_Superman_»11-Oct-09 15:35
professional«_Superman_»11-Oct-09 15:35 
GeneralRe: OnPaint Notification question Pin
ForNow11-Oct-09 16:02
ForNow11-Oct-09 16:02 
QuestionLocalizing MFC standard strings Pin
_Andrew11-Oct-09 11:32
_Andrew11-Oct-09 11:32 
GeneralRe: Localizing MFC standard strings Pin
David Crow12-Oct-09 3:12
David Crow12-Oct-09 3:12 
QuestionFinished drawing dialog Pin
clint198211-Oct-09 9:52
clint198211-Oct-09 9:52 
AnswerRe: Finished drawing dialog Pin
Emulator ®11-Oct-09 9:54
Emulator ®11-Oct-09 9:54 
QuestionRe: Finished drawing dialog Pin
clint198211-Oct-09 9:57
clint198211-Oct-09 9:57 
AnswerRe: Finished drawing dialog Pin
Emulator ®11-Oct-09 10:06
Emulator ®11-Oct-09 10:06 
QuestionRe: Finished drawing dialog Pin
clint198211-Oct-09 10:09
clint198211-Oct-09 10:09 

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.