Thread: Reading a file from ./program -f < filename

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    Reading a file from ./program -f < filename

    Can anybody provide an example how to read a file given a following construct:

    Code:
    ./program -f < filename
    where -f is some flag and there can be many other flags

    I know how to deal with flags but this construction is confusing
    thnx

    PS. ok attachment, i need just filename from stdin not the actual pointer. i need to pretend that the stuff defined in <filename part is just a filename and not actual pointer
    Last edited by baxy; 05-30-2012 at 03:45 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > ./program -f < filename
    This means you read from stdin, using fgets() or scanf() or getchar() in whatever combination makes you happy.

    > ./program -f filename
    This means "filename" is in argv[2]
    You can then fopen(argv[2]) for example, then read the file as much as you want to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in a filename from shell
    By Daerogami in forum C Programming
    Replies: 12
    Last Post: 10-25-2010, 06:32 PM
  2. reading in a filename correcty
    By bruiserbob555 in forum C Programming
    Replies: 5
    Last Post: 04-07-2010, 08:46 PM
  3. Reading Filename
    By C_ntua in forum C# Programming
    Replies: 6
    Last Post: 10-13-2008, 09:28 AM
  4. Getting filename of my program
    By iwabee in forum C Programming
    Replies: 10
    Last Post: 09-22-2004, 07:35 AM
  5. Getting the name of a file reading to program
    By DarkAbyss in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2003, 10:14 AM