ProgrammingHard
char s[] = "one two three"; int w = 0; for (char *t = strtok(s, " "); t; t = strtok(NULL, " ")) w++; printf("%d", w); What is printed?
- A. 4
- B. 3
- C. 5
- D. 2
Correct answer: B. 3
strtok skips the empty field between the two spaces, so the tokens are one, two and three.
More C Programming questions
- int n = 0; sscanf(" 42 abc", " %d", &n); printf("%d", n); What is printed?
- char a[] = "Level"; int pal = 1; for (int i = 0, j = 4; i < j; i++, j--) if (a[i] != a[j]) pal = 0; printf("%d", pal); What is printed?
- char a[] = "Level"; int pal = 1; for (int i = 0, j = 4; i < j; i++, j--) if (tolower(a[i]) != tolower(a[j])) pal = 0; printf("%d", pal)…
- printf("[%-6s|]", "ab"); What is printed?
- printf("%+d %05.1f", 5, 3.14159); What is printed?
- char s[] = "abc"; printf("%c", s[strlen(s) - 1]); What is printed?