#include #include #include int main() { char ch ; printf( "Enter a character:" ) ; ch = getchar() ; printf ( "%c\n" , ch ) ; printf( "A literal string.\n" ) ; printf( "Using format specifiers. %d %d\n" , 5, 10 ) ; int x1 ; printf ( "Enter a number:" ) ; scanf( "%d" , &x1) ; printf( "x1 is %d\n" , x1 ) ; //Input buffer has the end of line character in it //creating a problem. getchar() ; //read the end of line character printf ( "Enter a number -number-:" ) ; scanf( "-%d-" , &x1) ; printf( "x1 is %d\n" , x1 ) ; getchar() ; char buffer[256] ; printf( "Enter your full name:" ) ; //Does not read the full name scanf( "%s" , buffer ) ; printf( "%s\n" , buffer ) ; //Clear the buffer scanf( "%s" , buffer ) ; printf( "%s\n" , buffer ) ; char ch1 = getchar() ; printf( "ch1: %d\n" , ch1 ) ; printf( "Enter your full name:" ) ; memset( buffer, 0 , 256 ) ; //Will read the whole line // gets ( buffer ) ; // printf( "Using gets %s\n" , buffer ) ; size_t len = 256 ; char* line = NULL ; int readNumberOfCharacters = getline( &line, &len, stdin ) ; printf("Read line characters: %d\n" , readNumberOfCharacters ) ; if (readNumberOfCharacters == -1) { printf("Error reading line"); // Print error message if getline fails return 1; } else printf( "name: %s\n" , line ) ; free( line ) ; return ( 1) ; }