+ 3
[SOLVED] Driving license problem in C
I am trying to solve the sololearn problem of the driving license. I don't get what wrong with my code. If you do, well... I hope you tell me. Here is my code: https://code.sololearn.com/cHkD0Ydb0n1G/?ref=app Edit: I put a lot of comments to make it easy to read To find the problem go on code coach (in community) and write "license". Thank you for any help Reedit to help you helping me: The output is the same for both the case in which my name starts with Z (I am the last one) and in the case my name begins with A (I am the first one). In both cases there is only one agent available, so the output should be 100 minutes (5th) for Z and 20 minutes (1st) for A. However my output is 40 minutes for both cases... why!??
4 Respostas
+ 2
Change the call to scanf from
scanf( "%s %d", ... );
to scanf( "%s %d\n", ... );
otherwise the newline character will remain inside the input buffer just to be read by fgets(), which in turn stops once it encounters the newline character. As a consequence, input effectively remains empty and the position never advances.
+ 2
OMG I would have never looked for that. Thank you so much Shadow!
Thank you very very so much!!!
Before I read your answer I made other modifications to my solution that I haven't copied here, so I guess that your suggestion doesn't make the code work.
Should I delete the question anyway to prevent people getting driving license without studying?
Someone might get hurt 🤣 🤕
+ 1
There are already a lot of threads related to Code Coach problems such as this in the Q&A, and even more ready-made solutions in the Playground, so no need to trouble yourself there, especially if it is no working solution. Of course, if you feel like the thread will be of no benefit to others or you simply don't want to keep it around, feel free to delete it.
0
All right then I keep it. After all it's my first question, I am fond of it.