stdin question

This is a discussion on stdin question within the C Programming forums, part of the General Programming Boards category; hello! I want to use stdin twice. Is it possible at all? For example, when I use stdin while(!feof(stdin)) printf("%c", ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    13

    stdin question

    hello!

    I want to use stdin twice. Is it possible at all? For example, when I use stdin

    while(!feof(stdin)) printf("%c", getc(stdin));

    and now does the stdin exist in the memory anymore?

    I want to use the same stdin stream again.

    or must I copy the data in stdin to the memory first?

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    stdin is always open in your program unless you do something unadvisable like fclose it :-)
    *Cela*

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    ok, then how do I return to the beginning of stdin
    rewind(stdin);
    doest work

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    thanks

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    no actualy I want something something like this

    ./program < data // from command promt

    while (!feof(stdin){
    printf("%c",getc(stdin));
    }

    return to beginning of stdin.

    printf("\n\n\n");

    while (!feof(stdin){
    printf("%c",getc(stdin));
    }

    output should be:

    contest of file data
    3 gaps
    contest of file data
    Last edited by oomen3; 02-19-2003 at 12:11 PM.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    [oomen@localhost]./program < data

    the data is not command line argument but "<" send the data to the program as input stream

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by oomen3
    [oomen@localhost]./program < data

    the data is not command line argument but "<" send the data to the program as input stream
    The input stream is not rewindable. It is not a standard file. It is not something that stores an indefinate amount of input so that you can go back and read what happend a while ago.

    You'll have to do what Salem suggests. If you don't like it, buffer the input in your program as you read it, and go back and start reading from your internal buffer again.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. stdin question
    By audinue in forum C Programming
    Replies: 12
    Last Post: 01-11-2009, 01:57 AM
  3. struct question part 2
    By ronin in forum C Programming
    Replies: 4
    Last Post: 06-23-2003, 05:09 PM
  4. stdin question
    By SourceCode in forum C Programming
    Replies: 1
    Last Post: 04-10-2003, 08:50 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

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