Question: 2. Write a function my_strcpy(char str1[], char str2[], int str2_size, int p1, int p2) which copies the C-string in str1 (from index p1 to index
2. Write a function my_strcpy(char str1[], char str2[], int str2_size, int p1, int p2) which copies the C-string in str1 (from index p1 to index p2) to str2 (size is str2_size). Your function has to check if str2 has enough space. If there is no enough space in str2 to accommodate the string, print an error message but not copy anything to str2. Also write a driver program to test your function. Sample program output: str1 = I love C++ so much! Copy from str1 to str2 Start position: 3 End position: 13 >> Error >> str2 does not have enough space. >> Copy failed. Try again? (y) y str1 = I love C++ so much! Copy from str1 to str2 Start position: 3 End position: 10 str2 = love C++ Try again? (y) n Have a nice day!
2. Write a function my_strcpy(char str1[], char str2[], int str2_size, int p1, int p2) which copies the C-string in str1 (from index p1 to index p2) to str2 (size is str2_size). Your function has to check if str2 has enough space. If there is no enough space in str2 to accommodate the string, print an error message but not copy anything to str2. Also write a driver program to test your function. Sample program output: str1 = I love C++ so much! str1 = I love C++ so much! Copy from str1 to str2 ... Copy from str1 to str2 ... Start position: 3 Start position: 3 End position: 13 End position: 10 >> Error str2 = love C++ >> str2 does not have enough space. Try again? (y) n >> Copy failed. Try again? (y) y Have a nice day
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
