Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++


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
Updated 27-Dec-12 21:02pm
v2
Comments
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

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

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900