snprintf(buf, 8, "%s", "programming") – what does it return?
buf gets "program" (7 characters + '\0'), and the return value is the untruncated length, 11. A result ≥ the size means the output was cut.
C Input / Output · Exercise 1 of 4
Twelve multiple-choice questions on printf and scanf, their return values, line input, file modes, fseek, feof, text and binary mode and the standard streams. Pick an option to check your answer instantly.
snprintf(buf, 8, "%s", "programming") – what does it return?
buf gets "program" (7 characters + '\0'), and the return value is the untruncated length, 11. A result ≥ the size means the output was cut.
Is fflush(stdin) a portable way to discard pending input?
Some libraries allow it as an extension, but standard C does not. Portable code reads and discards: while ((c = getchar()) != '\n' && c != EOF) {}.
Timed online tests with instant scores and explanations.