Parsing input...

This is a discussion on Parsing input... within the C++ Programming forums, part of the General Programming Boards category; I want to make my prompt somewhat nicer in that a user can enter their input for a fraction in ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,456
    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, 05:02 PM
  3. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM
  4. Parsing input
    By Cicero in forum C Programming
    Replies: 11
    Last Post: 05-18-2002, 09:01 PM

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