Peter said:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
You don't seem to need the last one here.
int main(void) {
char input_string[50];
printf("Please enter conversion: ");
You need here additionally
fflush( stdout );
to make sure that that string is printed out immediately. Strings
that don't end in a '\n' can stay in the internal output buffers
of the printf() function and only the fflush() makes sure it gets
written to the screen in this case.
scanf("%s", input_string);
printf("The output is %s\n", input_string);
exit(0);
A "return 0;" or "return EXIT_SUCCESS;" will do here perfectly well,
no reason to kill the program;-)
Why does this code ignore any input text after a space?
Because scanf() always stops at spaces when reading in a string
(unless you tell it otherwise), assuming that that's the end of
the input string. The way to tell scanf() not to stop at spaces
is using
scanf("%[^\n]", input_string);
The "%[^\n]" tells scanf() only to stop on a newline character. But
than you still have a potential problem: if the user enters more
than 49 characters scanf() will happily write them past the end of
your 'input_string' array and then in principle everything can
happen (it may even seem to work). So you better make that
scanf("%49[^\n]", input_string);
to tell scanf() to accept not more than the 49 characters fitting
into the buffer (don't forget about the trailing '\0' that's needed
at the end of the string).
Since you seem to want to read a simple line it should be a lot
simpler to use fgets() here instead of scanf() (and never, ever
use gets(), it's horribly broken!). scanf() is rather difficult
to use correctly for reading user input and typically it's a lot
easier to simply read in a whole line with fgets() and then to
take that apart as necessary. That's also true if you e.g. want
an integer as input from the user - if the user types in some-
thing else it's difficult to catch that correctly with scanf()
and way much easier to deal with if you have the whole line and
can analyze it carefully. It's rumored that there are only very
few people who got the hang of using scanf() to savely read in
user input;-)
Regards, Jens