Click here to Skip to main content
15,926,857 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Why is my C program crashing? Pin
kakan7-Dec-06 21:48
professionalkakan7-Dec-06 21:48 
GeneralRe: Why is my C program crashing? Pin
<color>Aljechin 7-Dec-06 21:56
<color>Aljechin 7-Dec-06 21:56 
GeneralRe: Why is my C program crashing? Pin
kakan7-Dec-06 22:15
professionalkakan7-Dec-06 22:15 
GeneralRe: Why is my C program crashing? Pin
CodeMak7-Dec-06 22:22
CodeMak7-Dec-06 22:22 
GeneralRe: Why is my C program crashing? Pin
Christian Graus7-Dec-06 22:43
protectorChristian Graus7-Dec-06 22:43 
GeneralRe: Why is my C program crashing? Pin
CodeMak7-Dec-06 23:28
CodeMak7-Dec-06 23:28 
GeneralRe: Why is my C program crashing? Pin
Christian Graus7-Dec-06 23:34
protectorChristian Graus7-Dec-06 23:34 
GeneralRe: Why is my C program crashing? Pin
David Crow8-Dec-06 3:44
David Crow8-Dec-06 3:44 
Aljechin wrote:
Sorry but I am just curious why it's not working? I am not expert like you guys. Please help me.


What are you not understanding? It's been explained several different ways. In your code snippet, dest is not pointing to a valid (i.e., allocated) memory location. Until it is, you cannot copy characters to it from source. strcpy() would behave in the same fashion had you used:

char *source = "Hello", *dest = "";
strcpy(dest, source);
One solution is to use:

char *source = "Hello", dest[6] = "";
strcpy(dest, source);
Another would be:

char *source = "Hello", *dest = new char[6];
strcpy(dest, source);



"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

"Judge not by the eye but by the heart." - Native American Proverb


AnswerRe: Why is my C program crashing? Pin
Michael Dunn8-Dec-06 6:13
sitebuilderMichael Dunn8-Dec-06 6:13 
GeneralRe: Why is my C program crashing? Pin
<color>Aljechin 29-Dec-06 20:25
<color>Aljechin 29-Dec-06 20:25 
QuestionHow to search for a file.. Pin
Shah Satish7-Dec-06 21:10
Shah Satish7-Dec-06 21:10 
AnswerRe: How to search for a file.. Pin
Hamid_RT7-Dec-06 21:20
Hamid_RT7-Dec-06 21:20 
GeneralRe: How to search for a file.. Pin
Shah Satish7-Dec-06 21:48
Shah Satish7-Dec-06 21:48 
GeneralRe: How to search for a file.. Pin
Hamid_RT7-Dec-06 21:59
Hamid_RT7-Dec-06 21:59 
GeneralRe: How to search for a file.. Pin
Shah Satish8-Dec-06 23:27
Shah Satish8-Dec-06 23:27 
GeneralRe: How to search for a file.. Pin
Hamid_RT9-Dec-06 21:12
Hamid_RT9-Dec-06 21:12 
QuestionRe: How to search for a file.. Pin
David Crow8-Dec-06 3:47
David Crow8-Dec-06 3:47 
AnswerRe: How to search for a file.. Pin
Shah Satish8-Dec-06 4:23
Shah Satish8-Dec-06 4:23 
QuestionRe: How to search for a file.. Pin
David Crow8-Dec-06 4:32
David Crow8-Dec-06 4:32 
AnswerRe: How to search for a file.. Pin
Shah Satish8-Dec-06 23:24
Shah Satish8-Dec-06 23:24 
GeneralRe: How to search for a file.. Pin
David Crow11-Dec-06 3:06
David Crow11-Dec-06 3:06 
GeneralRe: How to search for a file.. Pin
Shah Satish8-Dec-06 23:25
Shah Satish8-Dec-06 23:25 
AnswerRe: How to search for a file.. Pin
Rajesh R Subramanian7-Dec-06 21:22
professionalRajesh R Subramanian7-Dec-06 21:22 
GeneralRe: How to search for a file.. Pin
Shah Satish7-Dec-06 21:47
Shah Satish7-Dec-06 21:47 
GeneralRe: How to search for a file.. Pin
Rajesh R Subramanian7-Dec-06 21:51
professionalRajesh R Subramanian7-Dec-06 21:51 

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.