Exforsys
+ Reply to Thread
Results 1 to 2 of 2

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. ...

  1. #1
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    144

    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.


  2. #2
    rachelle is offline Member Array
    Join Date
    Apr 2006
    Answers
    97
    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.


Latest Article

Network Security Risk Assessment and Measurement

Read More...