ProgrammingHard
char s[] = "a b,c"; int count = 0; for (char *t = strtok(s, " ,"); t; t = strtok(NULL, " ,")) count++; printf("%d", count); What is printed?
- A. 3
- B. 2
- C. 4
- D. 5
Correct answer: A. 3
strtok treats both the space and the comma as separators, so the tokens are a, b and c.
More C Programming questions
- char s[] = "abc"; char t[sizeof s]; strcpy(t, s); t[0] = 'X'; printf("%s%s", s, t); What is printed?
- printf("%zu", strlen("n")); What is printed?
- printf("%d", strlen("a0b")); What is printed?
- char s = "x"; char t[2] = {'y', '0'}; int r = strcmp(s, t); What does r look like?
- printf("[%03d]", 7); What is printed?
- printf("[%5s|%-5s]", "ab", "cd"); What is printed?