Thread: Parsing input...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    98

    Parsing input...

    I want to make my prompt somewhat nicer in that a user can enter their input for a fraction in the normal fashion:

    i.e. 4/5 6/7

    and be able to store the numerators and denominators on the programming side.

    i.e.

    a = 4
    b = 5
    c = 6
    d = 7

    How would I go about doing this?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    For this one... I think this should do:
    Code:
    int num[4];
    char op[2];
    char temp;
    cin >> num[0] >> op[0] >> num[1] >> temp >> num[2] >> op[1] >> num[3];
    Obviously, if you want longer inputs or more complex ones, you will have to read it all in one go and parse it from there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    98
    Quote Originally Posted by Elysia View Post
    For this one... I think this should do:
    Code:
    int num[4];
    char op[2];
    char temp;
    cin >> num[0] >> op[0] >> num[1] >> temp >> num[2] >> op[1] >> num[3];
    Obviously, if you want longer inputs or more complex ones, you will have to read it all in one go and parse it from there.
    Thought so, was just wondering if there was a very simple way to do it depending on the length/complexity of the input. Got it, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  2. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  3. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM
  4. Parsing input
    By Cicero in forum C Programming
    Replies: 11
    Last Post: 05-18-2002, 09:01 PM