Here’s my code…
char* m1;
char* m2 = "sth";
strcpy(m1, m2);
That code threw run-time errors, so I tried…
char m1[];
char m2[] = "sth";
That can run with no errors. However, I want to use…
char* s
What sould I do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Problem is you are not allocating any memory to store the result of the strcpy method. You need:
Than you can do the strcpy
And in the end you have to free any dynamically allocated memory a.g.
m2 is allocated statically and doesn’t has to be freed.