Answer the question
In order to leave comments, you need to log in
Why is it displaying the rest of the line?
char str_[32];
fgets(str_, 30, stdin);
printf("%s\n", str_);
Answer the question
In order to leave comments, you need to log in
printf("%s\n", str_);
I think the problem is in this place.
Try outputting like this:
And here's how fgets() works:
The fgets() function reads at most num-1 characters from the input stream and places them in the character array pointed to by str. Characters are read until a newline or EOF is read, or until the specified limit is reached. At the end of reading characters, a null character is placed immediately after the last character. The newline character is preserved and becomes part of the array addressed by the str element.
How to explain it
void PrintStr(const char *str)
{
int size = strlen(str);
for(int i = 0; i < size; ++i)
std::cout << str[i];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question