06 September 2023 06:42:05 PM ppc_fgets_demo(): C version Demonstrate how fgets() reads data from a buffer. # include # include # define BUFLEN 16 int main ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: ppc_fgets_demo() shows how fgets() reads character data into a buffer. Licensing: This code is distributed under the GNU LGPL license. Modified: 05 September 2023 Author: John Burkardt Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 */ { char buf[BUFLEN]; timestamp ( ); printf ( "\n" ); printf ( "ppc_fgets_demo():\n" ); printf ( " C version\n" ); printf ( " Demonstrate how fgets() reads data from a buffer.\n" ); printf ( "\n" ); while ( fgets ( buf, BUFLEN, stdin ) != NULL ) { printf ( "%s", buf ); } /* Terminate. */ printf ( "\n" ); printf ( "ppc_fgets_demo():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the GNU LGPL license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE } ppc_fgets_demo(): Normal end of execution. 06 September 2023 06:42:05 PM