Here's a program I wrote to copy a string constant.
When the program is run it crashes. Why is this happening ?
#include <stdio.h>
char *alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char c;
char *l;
main(){
while((c = *alpha++)!='\0')
*l++ = *alpha;
printf("%s\n",l);
}
char *l = malloc(strlen(alpha)+1);. PS: Definitely familiarize yourself with the debugger. It would show you exactly where it's crashing ... which is important to understanding why, and fixing the problem. IMHO...