Answer the question
In order to leave comments, you need to log in
How to enter a string without a line terminator?
#include <stdio.h>
int main()
{
char country[64] = "", city[16] = "";
fgets(country, 64, stdin);
fgets(city, 16, stdin);
printf("The capital of the state of %s is the city of %s", country, city);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Well, yes, that's right:
The fgets() function reads up to num-1 characters from stream and puts them into the character array pointed to by str. Characters are read until a newline, EOF, or the specified limit is reached. At the end of the reading, the null character is placed in the str array immediately after the last read character. The "newline" character on reading will be preserved and become part of the str array.
The gets() function reads characters from stdin and puts them into the character array pointed to by str. Characters are read until a newline or EOF is encountered. The "newline" character is not made part of the string, but is translated into the null character that terminates the string.
country[strlen(country)-1] = 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question