Sentinel value - terminating integer input into int array

This is a discussion on Sentinel value - terminating integer input into int array within the C Programming forums, part of the General Programming Boards category; I know how to terminate user input using scanf for char arrays...but what type of value can be used in ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Cool Sentinel value - terminating integer input into int array

    I know how to terminate user input using scanf for char arrays...but what type of value can be used in the case for int input? Obviously not some int, if you want to allow the user to input any range of viable integers.

    So, I guess my question, what would be a good sentinel value for exiting the loop containing the scanf statements?

    I know I could do conversion from char to int; but going that route seems overly complicated for this endeavor...

    thanks,

    shelley

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but what type of value can be used in the case for int input?
    Separate the sentinel value from the valid input by asking if the user wants to continue or entering a series of integers such as 0 then EOF to signify the end of input.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    2
    [QUOTE]Originally posted by Prelude
    [B]>but what type of value can be used in the case for int input?
    Separate the sentinel value from the valid input by asking if the user wants to continue or entering a series of integers such as 0 then EOF to signify the end of input.


    Hi, thanks for replying so quick.

    I thought of that, but just wondered how to flag an input, using scanf(%d), such that the complier wouldn't go crazy, , i.e., how to submit EOF in this case without a seperate scanf statment? Is there such an animal for integer input streams?

    shelley

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

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