#include <stdio.h>
void main () {
char str[5];
fgets(str, sizeof(str), stdin);
printf("%s.", str);
}
I wrote this simple code in C, and I'm trying to print a string and a dot in a single line, but whenever I enter a string with 3 or less characters, the output has a line break after the string.
Input:
abc
Output:
abc
.
If I enter something with exactly 4 characters, the output is as I want, without the line break.
I've tried using the gets() and scanf() functions and they worked well, but I cannot use them.
Does someone know why it happens and a solution?