This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

scanf("%[^\n]",string) question


hi all , 
    
   I am using Linux redhat 6.2 nd using gcc 
  ((egcs-1.1.2) compiler to compile my program. I am
facing problem with scanf(). The sample Program looks
like this

#include<stdio.h>
main()
{
char a[20],b[30] ;

printf("\nEnter Your FName & Last Name:");
--->scanf("%[^\n]",a) ;

printf("\nEnter Your Department") ;
fflush(stdin) ;
--->scanf("%[^\n]",b) ;

printf("\nThe Name Entered is %s",a) ;
printf("\nThe Department Entered is %s\n",b); 

I am compiling my prog like this
---->gcc try.c

When I run the Program It accepts the value with no
errors But when it encounters the next scanf statment 
it ignores it nd move to the next statement.

Console result:

Scanning 1st time
--->Enter Your FName & Last Name:Puneet Singh
(scanf accepts it fine)

Scanning 2nd time
Enter Your Department
(compiler ignores it moves to the next statement)

The Name Entered is Puneet Singh
The Department Entered is ì•q‚ \@8ûÿ¿p©    

Is it a bug or is there a problem at my side of using
this properly
plz suggest 
regards 
Puneet


___________________________________________________________________
*NEW*   Yahoo! Messenger for SMS. Now on your Cellforce phone    *NEW*
        Visit http://in.mobile.yahoo.com/smsmgr_signin.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]