Hi to all... I checked the FAQ and some tutorials over the net regarding not use
scanf or gets just use fgets to control buffer. I created this code for a test but it seems
like the excess buffer is not removed but the other fgets received it and it won't allow
me to input another value.
I can't think of any resolution to this problem. Thanks for the help in advance..Code:#include <stdlib.h> #include <string.h> #include <stdio.h> int main() { char name[ 22 ]; char age[ 4 ]; int length; char *newlineName; char *newlineAge; fputs( "Enter name: (20 maximum characters) ", stdout ); if( fgets( name, 22, stdin ) ) { newlineName = strchr( name, '\n' ); if( newlineName ) *newlineName = '\0'; } fputs( "Enter age: ", stdout ); if( fgets( age, 2, stdin ) ) { newlineAge = strchr( age, '\n' ); if( newlineAge ) *newlineAge = '\0'; } fputs( "Your name is: " , stdout ); fputs( name, stdout ); fputs( "\nYour age is: ", stdout ); fputs( age, stdout ); return 0; }



LinkBack URL
About LinkBacks



