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.


C
char field[] = ",red;;blue,green;";
char *first = strtok(field, ",;");
char *second = strtok(NULL, ",;");
char *third = strtok(NULL, ",;");


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.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Strings and string.h Questions: