A stock-adjustment tool accepts signed decimal counts of items. Its validation requires at least one converted digit and no trailing characters. Assume stdlib.h and stdio.h are included, all converted values fit in long, and no range errors occur.
const char *tokens[] = {"12", "7kg", "bad", "0", "-5"}; int accepted = 0; long total = 0; for (int i = 0; i != 5; ++i) { char *end; long value = strtol(tokens[i], &end, 10); if (end != tokens[i] && *end == '\0') { ++accepted; total += value; } } printf("%d %ld\n", accepted, total);
Find the original number of accepted inputs and the original total adjustment in items. Then run the fragment again from its initial state, replacing only the if condition with value != 0. Find the modified number of accepted inputs and modified total adjustment in items. Enter all four answers as exact integers.
Unlock full course notes by signing up
Trace partial input completion
A logger runs the following code independently for each input row. Each input is followed by a newline, and no input errors occur. Complete the table with the return value, final sample count, and final duration in seconds. Use exact integers or short decimals.
Reserve space for string termination
A sensor utility reads one whitespace-delimited label into char label[7] using scanf. Supply the complete string conversion specification with the largest width that fits the array while reserving space for the terminating null character: ________.
Track bounded line reads
A label-reading utility includes stdio.h and executes this fragment. Standard input contains alpha, a newline, Z9, and a final newline, followed by end-of-input. All three calls succeed without input errors.
Complete the table immediately after each call. Count the input characters stored, excluding the terminating '\0'. Enter exact integers for counts, yes or no for whether a newline is stored, and the next unread character or none if no input characters remain.
Follow whitespace across consecutive reads
A command reader executes the code below with input consisting of 52 Q followed by a newline. Assume all input is available and no input errors occur. Which statements about the calls are true? Select all that apply.