Click here to Skip to main content
12,831,676 members (32,700 online)
Rate this:
Please Sign up or sign in to vote.
See more: C

int flag=1,n;
    char string[200];
    printf("Enter number <0-5> : \n");
    printf("Insert string <bigger than the number above> : ");

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?
Posted 27-Dec-12 22:01pm
Updated 27-Dec-12 22:02pm
walterhevedeich 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 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
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.


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100