skipping a character during input

This is a discussion on skipping a character during input within the C Programming forums, part of the General Programming Boards category; i need some hints on how solve this problem: what i want is input a series of int numbers in ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    skipping a character during input

    i need some hints on how solve this problem:

    what i want is input a series of int numbers in an array. however the input involves a comma between these number.

    for example the input is

    Code:
    3, 1
    (with a comma between 3 and 1)



    without the comma, ie,
    Code:
    3 1
    it is easy program because i just loop with scanf

    but i'm getting stuck if there is a comma involved. is there a built-n function for this problem?

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    scanf("%d%*[, ]%d",&a,&b);
    accept  
    3   2
    3,2
    3 ,     5
    But not 
    3
    5
    use %*[, \n] if you want that ..
    Always read the doc!

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by sanji2011 View Post
    i need some hints on how solve this problem:

    what i want is input a series of int numbers in an array. however the input involves a comma between these number.

    for example the input is

    Code:
    3, 1
    (with a comma between 3 and 1)



    without the comma, ie,
    Code:
    3 1
    it is easy program because i just loop with scanf

    but i'm getting stuck if there is a comma involved. is there a built-n function for this problem?
    Note the coma in the format string...
    Code:
    scanf("%d,%d",&a,&b);
    Yes, it's that easy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple Character Input.
    By mintsmike in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 01:15 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. character input using fgetc() code???
    By lesrhac03 in forum C Programming
    Replies: 3
    Last Post: 03-27-2008, 10:55 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Character handling help
    By vandalay in forum C Programming
    Replies: 18
    Last Post: 03-29-2004, 04:32 PM

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