I’ve seen, here and elsewhere, many questions that, to get input data, use something like this:
...
printf("What's your name? ");
scanf("%s",name);
...
This is very reminiscent of the old BASIC days (INPUT for those who remember it).
The majority of those questions, if not all, are from people just learning C and are homeworks or example taken from their book.
I clearly remember that when I learned C I was told that this type of question/answer style was not a good practice for getting user input. The “Right Way” was either to get parameters on the command line (argv[...]) or reading from a data file to be parsed with fgets(). When user friendliness was a must, termio and friends had to be used.
Now, I wonder if anything changed in the past years. Are people thaught to structure user interaction as a set question/answer now?
I can only see disadvantages in using the printf()/scanf() approach, the main one being the diversity of terminals (^H anyone?) that could make difficult for the user to correct mistakes.
Could anyone point me to concrete advantages of this approach?
This structure is easy to explain and easy to learn, which is why it appears in so many introductory materials. Doing user input “the right way” in C can appear fairly daunting to a neophyte, especially when you have to deal with tokenizing and conversions.
However, I agree that it would be valuable for introductory materials to demonstrate more robust methods for handling user input.