Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write in C language 5. [8] Write a function with prototype » void string_copy(co

ID: 3595080 • Letter: W

Question

Write in C language

5. [8] Write a function with prototype » void string_copy(const char source[], char destination[], int n); This function copies string source to string destination. Parameter n represents the size of array destination. If the latter array is not sufficiently large to hold the whole source string then only the prefix of the string which has room in the latter array should be copied. Note that after copying, the null character should also be included to mark the end of string destination. Write a program to test your You are not allowed to use any function declared in string.h You may write a function which returns the length of a string and use it if you need it. Recall that a string is a char array with the null character marking the end. The length of the string is the number of characters in the array appearing before the null character.

Explanation / Answer

#include <stdio.h>
void string_copy(char source[], char destination[], int n) {
int i;
for(i=0;i<n && source[i] != '';i++) {
destination[i] = source[i];
}
destination[i]='';
}
int main()
{
char source[50] = "abcdef";
char destination[50];
string_copy(source, destination, 50);
printf("source = %s destination = %s ",source,destination);

return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote