Getting Input

This is a discussion on Getting Input within the C Programming forums, part of the General Programming Boards category; I have the following code: Code: printf("Enter order of matrix A (e.g. 3x5) : "); scanf("%dx%d", &rowsa, &colsa); This seperates ...

  1. #1
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    Getting Input

    I have the following code:
    Code:
    printf("Enter order of matrix A (e.g. 3x5) : ");
    scanf("%dx%d", &rowsa, &colsa);
    This seperates 3 and 5 into rowsa and colsa when the
    user types 3x5

    how do i generalise this to any character between two numbers?
    i.e., i want it to work when the user types
    2y5
    2 5
    2-4
    23-4
    23 44

    also, if possible...
    22--- 44
    (more than one space, character in between the numbers)

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    what you could do is fgets() the input into a string, then extract the first digits into a column array and the second to a row array. Then simply use atoi() to get the integer value.

  3. #3
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    thanks

    thanks for the tip
    [edit]
    it is working now
    [/edit]
    Last edited by moonwalker; 08-03-2002 at 10:46 PM.

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Anytime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem grabbing k/b input
    By falcon9 in forum C Programming
    Replies: 2
    Last Post: 10-28-2007, 12:47 PM
  2. continues input
    By Matty_Alan in forum C Programming
    Replies: 2
    Last Post: 06-22-2007, 11:04 PM
  3. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-30-2007, 12:16 AM
  4. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 04:54 AM
  5. Simple Console Input for Beginners
    By jlou in forum C++ Programming
    Replies: 0
    Last Post: 06-21-2005, 02:50 PM

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