To tell you the truth. In actual code in production almost everyone uses something created to read because everything that exists has problems. This runs with several C functions, and this is one of the problems of a language that wants to provide only the basics and does not want to evolve (although this has its advantages as well).
For exercises and simple codes it depends on what you want. But I can already tell you that cleaning the buffer does not make sense and who knows how to program in C actually knows this. There is a myth of using fflush(stdin)
. It even works on some compiler (because they chose to put it in their default library), but this is not standard C, so it should not use. Unless it's programming in a C. dialect. But if it's learning, learn right.
scanf()
is not usually a good option , except for the basic good. There are techniques that help with some problems, but you can not control all situations. You can use it for quick exercise.
gets_s()
is much simpler and is only available in C11 compilers which is a bit rare to have implemented. If you use it, you will not be able to carry it.
Do not use either, use fgets()
. This function is designed for more complex readings, but even it is not good at all and may have buffer problem. And it is a little chatinha to use, has to understand how data comes, eventually manipulate it, but programming in C and not understanding in depth what you are doing does not work.
At least you did not think about gets()
that is insecure, it's already an advantage.
See also How to read from stdin in C? where it shows options.
If you do not commit yourself fully to learning C, you should not try hard. I am in favor of learning C as a way of understanding what is happening, but I do not think you need to learn every detail if you do not work as a C programmer. If it is only to learn to program and not C itself, it matters little what to use, because what matters is other things of language. If you are going to learn the language for day-to-day use then both are bad.