Read a Whole Line
Completed
Read a full line with fgets, remove the trailing new line, and print it in brackets with its length.
Input
One line (may contain spaces).
Output
[TEXT] N
Example
Input
hello big world
Output
[hello big world] 15
Editor
C
Hints
scanf("%s") stops at a space; fgets reads the whole line.
strcspn(line, "\n") finds the new line.
Solution explanation
fgets keeps the new line character, so it's usually removed right after reading.
Show solution
#include <stdio.h>
#include <string.h>
int main() {
char line[200];
fgets(line, 200, stdin);
line[strcspn(line, "\n")] = '\0';
printf("[%s] %d\n", line, (int) strlen(line));
return 0;
}