C Programming, 4th Ed – Correction to pages 110/111

It is now recommended that fgets() be used in place of the gets() function that has been marked as deprecated. So the example on page 110/111 of “C Programming in easy steps” should appear as:

 

#include <stdio.h>

 

int main()

{

char str[51] ;

 

printf( “\nEnter up to 50 characters with spaces:\n” ) ;

fgets( str, sizeof( str ), stdin);

 

printf( “fgets() read: ” ) ;

puts( str ) ;

 

printf( “\nEnter up to 50 characters with spaces:\n” ) ;

scanf( “%s”, str ) ;

printf( “scanf() read: %s\n” , str ) ;

 

return 0 ;

 

}

Leave a comment

You must be logged in to post a comment.