Question
Complete the C function to copy at most n characters from source starting at start_index into destination, ensuring destination is null-terminated. Assume destination has enough allocated memory. #include #include // For debugging, not strictly needed void safe_copy_substring(char* destination, const char* source, int start_index, int
n) {   int source_len = strlen(source);   if (start_index >= source_len) {     destination[0] = '\0'; // Source index out of bounds, return empty string     return;   }   int chars_to_copy = n;   if (start_index + chars_to_copy > source_len) {     chars_to_copy = source_len - start_index;   }   strncpy(destination, _________, chars_to_copy); // Line to complete   destination[chars_to_copy] = '\0'; // Ensure null-termination }
Solution
Correct Answer: E (Both source + start_index and &source[start_index] correctly provide a pointer to the starting character of the substring within source.)
More IT Operating System Questions
- Which of these AI approaches involves agents learning by interacting with their environment?
- The "load factor" of a hash table is a critical metric. What does it represent?
- The Process Control Block (PCB) does not typically contain which of the following information?
- Consider a system with 4 CPU cores. If there are 8 user-level threads in a single process, what is the maximum number of these threads that can execute con...
- Transfer function of closed loop system with negative feedback is defined as___
- Which of the following statements accurately describes Third Normal Form (3NF) in database normalization?
- Which algorithmic paradigm does the Floyd-Warshall algorithm primarily use?
- The following Python code attempts to call a method from the parent class, but it's using an outdated or incorrect syntax. How should it be corrected? cla...
- Predict the output list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5, 6, 7 ] print "list1[0]: ", list1[0]
- Frame relay :