the title says it all.
here's an example code i tested too:
Code:#include <stdio.h> #include <string.h> char * str; int main( void ) { strcpy(str, "Hello World!"); return 0; }
the title says it all.
here's an example code i tested too:
Code:#include <stdio.h> #include <string.h> char * str; int main( void ) { strcpy(str, "Hello World!"); return 0; }
str is just a pointer. It has no space to hold the string. What you want is a char array with at least enough space to hold the characters (including the null terminating character), and it may as well be declared inside main.
Code:#include <stdio.h> #include <string.h> int main(void) { char str[100]; strcpy(str, "Hello World!"); printf("%s\n", str); return 0; }