Reading a string input with spaces in between words can be tricky. There are two functions you can use here its scanf() and fgets(). Both can be used to read in strings from console safely. By safe I mean not overflowing your buffer.

Using fgets()

This is the common way of retrieving input including spaces safely.

#include 
 
int main( int argc, char* argv[] ) {
 char buffer[1024];
 
 printf( "Please enter a string: " );
 fgets( buffer, 1024, stdin );
 printf( "You entered: %s", buffer );
 return 0;
}

Using scanf()

This is the one I prefer to use over fgets(). Continue reading