Asked by Richard Sullivan on May 23, 2024

verifed

Verified

Complete the following function:
/* copy string2 to string1 */
Void strcopy(char string1[], char string2[])
{
Int i = 0;
While (string2[i] != '\0')
{
String1[i] = string2[i];
I++;
}
____
}

A) return;
B) string1[i - 1] = '\0';
C) string1[i] = '\0';
D) string1[i + 1] = '\0';

End-Of-String Character

A special character used in programming to mark the termination of a string, often represented as '\0' in C and C++.

String1[i]

String1[i] refers to accessing the ith character in the string named String1 in programming, where i is an index starting from 0.

  • Manipulate strings in C using functions like strcpy, strcat, and custom functions.
  • Recognize the importance of proper termination in string copying and manipulation operations.
verifed

Verified Answer

LC
Lexxus CharlesMay 24, 2024
Final Answer :
C
Explanation :
To correctly copy a string in C, including its null terminator, you should assign the null character ('\0') to the next position in string1 after the last copied character. This ensures the copied string is properly terminated. Option C does this correctly by placing '\0' at the index `i`, which is right after the last copied character from string2.