My c++ code for the problem GUESSG from june challenge is partially accepted,but similar
implementation in c is giving WA.Can I know the reason why the c code is not working.
The cpp code - CodeChef: Practical coding for everyone
The c code - CodeChef: Practical coding for everyone
Both endl
and \n
serve the same purpose in C++ and c – they insert a new line. However, the key difference between them is that endl
causes a flushing of the output buffer every time it is called, whereas \n
does not.
So whenever you are using C language and ‘\n’ to solve interactive problem don’t forget to use fflush everytime you output something.
Check Out: std::endl vs n in C++ - GeeksforGeeks
3 Likes
As you said I have used fflush(stdout),but still the code is not working.
here’s my code - CodeChef: Practical coding for everyone
also use scanf("%*c%c",&c).
So what *c will do is it will ignore the newline and scan for the character.
as you are reading a character after reading an integer so without using scanf("%*c%c",&c) the first while loop iteration will take up the newline character as input and continue and blah blah…too much theory.
Simply use scanf("%*c%c",&c) instead of scanf("%c",&c).
Hope this would help.
1 Like