i want to add “/.” to a file name, for example,
i have file name “abc”, i want to get a name “abc/.abc”,
how to do it in C?
strcpy(“/.”,name) and strcat(“/.”,name) returned segmentation fault.
Thanks
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.
The first parameter to
strcatmust be a modifiable string with enough space allocated to hold the resulting string and the terminating zero byte. The first parameter tostrcpymust point to allocated, modifiable memory with sufficient space to hold the resulting copy of the string and the terminating zero byte. In both of your examples, you have passed a constant as the first parameter.Here’s some example code to do what you want: