r/C_Programming • • May 29 '26

Question HELP!!!!

   while(1){
        if(scanf(" %d",&input_choice)==1){
            break;
        };
        
        while(1){
            if(getchar()=='\n'){
                break;
            }
        }
    };
Guys what am i doing wrong can you please tell me .
 i am sorry if i am asking very basic thing . i read some documentation online but couldn't figure out what is going wrong 
0 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/Level-Pollution4993 May 29 '26

Yes you're right. I did not think thats what you were doing. And indeed with that loop added, the program runs indefinitely if you enter something like abc123 but works for purely int inputs like 123. Is that the same issue you were having?