Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C

int flag=1,n;
    char string[200];
    printf("Enter number <0-5> : \n");
    scanf("%d",&n);
    printf("Insert string <bigger than the number above> : ");
    while(flag)
    {
        gets(string);
        flag=CheckNumOfWords(string,n);
    }
Hi guys
so when i run the script it doesn't pause so i can enter my string, he skips the func "gets(string)", but when i remove the "scanf("%d",&n)" the "gets(string)" workes fine
any suggestions or comments?
tnx!
Posted 27-Dec-12 21:01pm
idobry388
Edited 27-Dec-12 21:02pm
v2
Comments
walterhevedeich at 28-Dec-12 3:35am
   
There were some issues and documented solutions on using scanf before gets and vice versa. Google "scanf before gets". The results suggests some solutions that you might want to try.
idobry at 28-Dec-12 3:40am
   
Thx mate i saw servel solution and i just added "fflush(stdin);" after my scanf and it worked flawless.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

None of those functions "cancels" anything. Execute this code under the debugger; and you will clearly see what goes on.
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 280
1 Sarvesh Kumar Gupta 238
2 Sergey Alexandrovich Kryukov 203
3 OriginalGriff 163
4 DamithSL 153


Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid