Click here to Skip to main content
15,913,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWhy is my C program crashing? Pin
<color>Aljechin 7-Dec-06 21:26
<color>Aljechin 7-Dec-06 21:26 
AnswerRe: Why is my C program crashing? Pin
Naveen7-Dec-06 21:30
Naveen7-Dec-06 21:30 
GeneralRe: Why is my C program crashing? Pin
<color>Aljechin 7-Dec-06 21:33
<color>Aljechin 7-Dec-06 21:33 
GeneralRe: Why is my C program crashing? Pin
kakan7-Dec-06 21:39
professionalkakan7-Dec-06 21:39 
GeneralRe: Why is my C program crashing? Pin
<color>Aljechin 7-Dec-06 21:42
<color>Aljechin 7-Dec-06 21:42 
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 
This really is basics, I suggest you read a book that covers C. It would make things clearer to you.

Your original code was this:

main()
{
     char *source = "Hi", *dest = "";
     while(*source++) *dest++ = *source;
}


A declaration like this:
char *source = "Hi"
is (normally) used for constant values (that doesn't change during the execution of the program).
If you want a buffer that can be modified, you'd better allocate it, like this:
char temp[50];
Now you have a buffer that can hold up to 50 characters. Use it as you wish, i.e. like this (as long as your source text doesn't exceed 49 charaters plus the terminating null character):
strcpy(temp, "Hello World");



Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

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 
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 

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.