The following program demonstrates the use of gets() and puts():
#include <stdio.h>
const int bufferSize = 80;
int main( void ) {
char stringBuffer[ bufferSize ];
printf( "Enter a string: " );
gets( stringBuffer );
puts( "You entered:" );
puts( stringBuffer );
}
This program first declares a string buffer. Next, it provides a user prompt, and then it reads the input into the string buffer withgets(). It then callsputs()twice—once to give a label string and again to write out what the user entered.
You may recall that this program is very similar to readString.c, which we created earlier. Copy the readString.cprogram into the readString2.cfile and modify it to match the preceding program. Save, compile, and run it. You should see something like the following output:
Notice that the C runtime gave a warning about using gets...