end of standard input

This is a discussion on end of standard input within the C++ Programming forums, part of the General Programming Boards category; Link to the problem here Code: 1 10 100 200 201 210 900 1000 If that's the input from standard ...

  1. #1
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696

    Smile end of standard input

    Link to the problem here
    Code:
    1 10
    100 200
    201 210
    900 1000
    If that's the input from standard input, how do we know when to stop reading. Isn't a sentinel value required?
    Last edited by alphaoide; 06-21-2004 at 04:14 PM.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  2. #2
    ZAK
    ZAK is offline
    Registered User
    Join Date
    May 2002
    Posts
    13
    That number is a starting value and an ending value the program description says that you must generate all the cycle lengths from i to j inclusively. This problem is neat on the theoretical model where it poses again a state of the haulting problem...briefly stated the haulting problem is: Given some program can you ascertain that it will always hault?" This question was posed by Alan Turing and Alonzo Church when they formalized computation theory Turing used a theoretical FSM known as a Turing machine adn Alonozo Church used lambda calculus Google for the Haulting Problem and you will get more information about this program and others like it.
    "Computer Science is no more about computers than astronomy is about telescopes"
    - E.W. Dijkstra

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,649
    The example algorithm used a sentinel value of 1.......

    You don't have to use a sentinel value, you could just keep reading while the stream is good.

    If it's for a class, ask the prof.

    gg

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    This is just one of samples of programming contest problems, whose solution could be submitted through email. I suppose the input would be from screen input therefore doing below won't work and 1 is the sentinel value for the algorithm, not the sentinel value for the *input*.
    Code:
    while (std::cin >> a >> b)
    {......}
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,649
    >> ... below won't work ...
    It works fine if you supply an EOF character - cntrl-Z for Dos/Windows, cntrl-D for *nix.
    Which means it will work nicely when redirecting input from a file, eg. "prog.exe < input.txt".

    gg

  6. #6
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    redirecting input from a file...yeah I forgot about that. So I guess that's what they will do with their automated submission system.
    Thnx a bunch
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  2. defaulting ifstream variable to standard input
    By risby in forum C++ Programming
    Replies: 16
    Last Post: 02-06-2008, 07:11 AM
  3. Parse Error At End Of Input?!?!?!?!?!
    By kas2002 in forum C++ Programming
    Replies: 3
    Last Post: 06-02-2002, 09:22 AM
  4. Reading integers until end of input
    By nivo in forum C Programming
    Replies: 7
    Last Post: 10-20-2001, 04:18 PM

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