Suppose I do like this to copy the string.
char str[] = \"\";
char *str2 = \"abc\";
strcpy(str, str2);
printf(\"%s\", str); // \"abc\"
printf(\"%d\", strlen(str
You are writing past the memory space allocated to str on the stack. You need to make sure you have the correct amount of space for str. In the example you mentioned, you need space for a, b, and c plus a null character to end the string, so this code should work:
char str[4];
char *str2 = "abc";
strcpy(str, str2);
printf("%s", str); // "abc"
printf("%d", strlen(str)); // 3