Thread: Taking chars into account.

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    19

    Question Taking chars into account.

    OK, not-so-hypothetical here:

    Say I had a input that, the majority of the time, expected an integer value. But, there is a single case where a char would be acceptable (ie instead of entering an integer, you'd press Q to enter a quit function).

    Is there a nice and clean way of doing this? I know scanf() wasn't designed to do this, and I'm stumped as to what other *scan*() function would do this.

    Thanks in Advance,
    kirby1024

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    41
    You could just always read in a char and when it's not a Q, then convert it to an integer (atoi()).

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    19
    But it's not going to be a single digit all the time (excuse me if I show my newbieness, but I thought that %c would mean only 1 character period, including numbers). Doing it that way, I'd have thought that I'd lose all digits after the first.

    Again, please tell me if my reasoning's faulty

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    41
    Then read in a string. =)

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    19
    :blink:

    Right. That just seemed so obvious...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bank Account Problem
    By JayBlay77 in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2009, 08:41 AM
  2. Taking brackets into account for calculator input
    By advancedk in forum C Programming
    Replies: 1
    Last Post: 09-30-2008, 02:02 PM
  3. Taking only first 100 chars of a string
    By lucaspewkas in forum C Programming
    Replies: 11
    Last Post: 04-27-2005, 11:44 PM
  4. Taking and skipping chars from files
    By Korhedron in forum C++ Programming
    Replies: 7
    Last Post: 07-23-2003, 03:50 PM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM