A program tests three independent copies using the code below, with string.h included. For each row, source points to a valid string containing exactly the listed text, with one byte per displayed character. Enter its length as an exact integer in bytes and enter yes or no to indicate whether a contains a terminating null character after the copy.
char a[5]; strncpy(a, source, sizeof a);
Unlock full course notes by signing up
Tracing a report name
A logging utility executes the following code with string.h included. Each displayed character occupies one byte. Find the final value of strlen(report) in bytes and the maximum number of additional non-null text bytes that could be appended while retaining a terminating null character. Give both answers as exact integers.
Finding text inside a log path
A log viewer runs the following searches. Assume string.h has been included and all statements execute successfully.
For each returned pointer, enter its byte offset, meaning its zero-based distance in bytes from the beginning of path. Use exact integers. Enter absent when the function returns a null pointer. Measure every offset from path, including the search that starts at path + 9.
Which string operations satisfy every condition?
A route-label utility declares char b[8] = "map";, with string.h included. Each proposed operation starts again from this original declaration, whose unused array elements are initialized to zero. Select every statement describing defined behavior that leaves b containing the stated valid C character string.
What tokenization leaves in storage
A log reader accepts either a comma or a semicolon between colour labels. It processes this mutable character array using strtok from string.h. Each later call passes NULL to continue scanning the same array; no other calls to strtok occur.
After all three calls, report the text beginning at third, without quotation marks; the zero-based byte offset of second from field; the number of comma or semicolon bytes still present anywhere in the original array; and the total number of null-character bytes in the entire array, including its original terminator. Enter all offsets and byte counts as exact integers. Count the whole array, including storage beyond its first null character.