1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Reading a file from command line

Discussion in 'C' started by Enig.Ma, Sep 4, 2010.

  1. Enig.Ma

    Enig.Ma New Member

    Sep 4, 2010
    Likes Received:
    Trophy Points:
    Hi guys,

    I recently have an assignment which will read a file from command line.

    e.g. myprogram < input

    1.) Would like to clarify that the way to read the inputs of the file would be to use fgets()? I have also tried using fscanf, and am not sure on which to go with. I have also searched through this forum and found sscanf, again, not sure on which one to use.

    2.) A second problem I have encountered is that I have no idea on how to "break" the input up into how I want them to be.

    The contents of the input file is a mixture of alphabets and numbers.

    My understanding of fgets() is that it would read the whole line as a string right? So, for example the line read is " c918 = a1203 ". Could you point me in the right direction as to how I would convert that string "c918 = a1203" to an integer -> 918, and hex -> a1203.

    Thanks guys, appreciate the help :)
  2. techgeek.in

    techgeek.in New Member

    Dec 20, 2009
    Likes Received:
    Trophy Points:
    EOC (exploitation of computers)..i m a Terminator.
    Not an alien!! for sure
    Home Page:
    Use command line argument then.... using command line argument just pass the file u want to read and inside ur program output the file content in the console using file operations....

Share This Page