Reading multiple values using fgets

This is a discussion on Reading multiple values using fgets within the C Programming forums, part of the General Programming Boards category; I'm working on a basic stack calculator. Input for pushin a number onto a stack is PUSH 5, PUSH 78 ...

  1. #1
    Stripes
    Guest

    Reading multiple values using fgets

    I'm working on a basic stack calculator. Input for pushin a number onto a stack is PUSH 5, PUSH 78 etc. I've been using fgets to get input from stdin, so does anyone have any ideas how to check for the numeric input using fgets? My idea was to remove the spaces in between and check if the next char is a number or not, but I'm not sure how to go about doing it.
    Any ideas?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yes, you should use scanf(). Or fscanf() with stdin as your file.

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Code:
    #include <ctype.h>
    See the help on various functions provided like isdigit(), ...

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >does anyone have any ideas how to check for the numeric input using fgets?
    fgets, sscanf, and thorough validation of the strings read.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading in a text file containing hex values
    By gaza2k1 in forum C Programming
    Replies: 34
    Last Post: 02-29-2008, 07:15 PM
  2. Replies: 3
    Last Post: 01-23-2006, 07:25 PM
  3. Reading values from a chart and creating a new one
    By sackyhack in forum C++ Programming
    Replies: 6
    Last Post: 08-25-2005, 05:53 PM
  4. get multiple values from INI file
    By hiya in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2005, 04:00 PM
  5. c function returning multiple values
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-23-2001, 10:09 AM

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