
- Forum
- Programming Talk
- C and C++
- Suggestion on Input
Suggestion on Input
This is a discussion on Suggestion on Input within the C and C++ forums, part of the Programming Talk category; I have used lot of scanf in the program. But all inputs are read from user and not from file. ...
-
Suggestion on Input
I have used lot of scanf in the program. But all inputs are read from user and not from file. In this scenario can I replace my scanf with fgets().Or is it that fgets() function can be used only for reading input from file. If I can use fgets() kindly tell me how should I make fgets() read input from user.
-
Yes you can very well replace your scanf with fgets(). fgets() function can be for reading input from file as well getting input from user depending on the needs of the user. As you might know fgets takes three arguments as its input. First is the char pointer, the second one is a integer denoting the maximum number of characters to be read per line and the third one would be a file pointer if the input is a file. For getting input from user change this third argument as stdin and your problem is solved and you can get input from user.

Reply With Quote





