Reading inputs from "< filename"

This is a discussion on Reading inputs from "< filename" within the C Programming forums, part of the General Programming Boards category; Hello, I have this project that goes like this... xspell -d dict -c <infile basically, I have this file 'dict', ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    3

    Reading inputs from "< filename"

    Hello, I have this project that goes like this...

    xspell -d dict -c <infile

    basically, I have this file 'dict', and file 'infile'; both contain list of words divided by newline. Infile compares with dict, and outputs only strings not in dict.
    I hashed dict file and just need to read the infile.

    how can I get hold of infile, i tried doing that with argv[i] but that didn't work.

    how can I make a token of words from infile?

    I had no problem with 'dict' because i just got that from argv[i].

    Thanks

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    The shell's < token puts the file on stdin for you. So instead of stdin reading from the keyboard like normal, it reads from the indicated file.

    Try this:
    Code:
    int main(void)
    {
      char word[4096];
    
      while(fgets(word, sizeof(word), stdin))
      {
        // blah blah blah
      }
    
      return 0;
    }
    Last edited by itsme86; 12-04-2009 at 02:00 PM.
    If you understand what you're doing, you're not learning anything.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    That's called reading from standard input (stdin).

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    3
    oh wow, I did not know that.
    Thank you very much for the quick replies. I got it to work.
    Code:
    int main (int argc, char *argv[])
    {
            FILE *fp;
            char word[45];
            while(fgets(word,45,stdin))
                    printf("%s",word);
    return 0;}
    Yea, in the project question, it said stdin, but I didn't know what it meant.
    Last edited by cooolway; 12-04-2009 at 01:59 PM.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    11
    hah, i take it you go to ryerson and have an assignment due tonight? :P

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    3
    lol yea.
    i saw other people on the net asking stuff related on our project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with reading from stream
    By movl0x1 in forum C Programming
    Replies: 7
    Last Post: 05-31-2007, 10:36 PM
  2. reading through an array
    By ammochck21 in forum C++ Programming
    Replies: 11
    Last Post: 11-29-2006, 06:02 AM
  3. Fun with reading hex
    By dpro in forum C++ Programming
    Replies: 7
    Last Post: 02-17-2006, 05:41 PM
  4. file reading
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-12-2002, 10:55 PM
  5. Reading from a file
    By Wiz_Nil in forum C++ Programming
    Replies: 1
    Last Post: 02-26-2002, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21