Question 6
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <ctype.h>
#include <stdio.h>
int main(void) {
char word[] = "hello";
printf("%c\n", toupper(word));
return 0;
}
- A toupper needs stdlib.h
- B toupper converts one character (an int); passing the array (a char pointer) is invalid – loop over the characters Correct
- C %c should be %s
- D There is no bug
Correct Answer: Option B
Convert each character: for (size_t i = 0; word[i]; i++) word[i] = (char) toupper((unsigned char) word[i]);.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!