Find the answer to your Linux question:
Results 1 to 2 of 2
Is it possible if I want to read userinput with fgets() that it comes from a file? Not into argv[]!...
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    5

    Userinput via file

    Is it possible if I want to read userinput with fgets() that it comes from a file? Not into argv[]!

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I'm not sure what you're asking.

    If you're asking whether you can get input from an arbitrary file which is not named in argv[], then sure, put that arbitrary filename into the call to fopen().

    But maybe you mean that you get the filename itself from a file. You can do that too.

    Open the file that contains the filename, using fopen(). Read the filename using fgets(). Then fclose() the file containing the filename in question.

    Open the file whose name you just read in the previous paragraph; use fopen() to do so. Read the data in that file with fgets(). When you're done, call fclose() for that file.

    Or did you mean something else?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...