Using gets and putchar : gets « stdio.h « C Tutorial






#include <stdio.h>

void reverse( const char * const sPtr );
   
int main()
{  
   char sentence[ 80 ];

   printf( "Enter a line of text:\n" );

   gets( sentence ); 

   printf( "\nThe line printed backwards is:\n" );
   reverse( sentence );

   return 0; 

}

void reverse( const char * const sPtr )
{  
   if ( sPtr[ 0 ] == '\0' ) {
      return; 
   }else { 
      reverse( &sPtr[ 1 ] );

      putchar( sPtr[ 0 ] ); 
   }
}
Enter a line of text:
string

The line printed backwards is:
gnirts








22.22.gets
22.22.1.gets
22.22.2.Using gets and putchar
22.22.3.gets() reads in only text