discard characters after space

This is a discussion on discard characters after space within the C Programming forums, part of the General Programming Boards category; hi, i am writing a program in c in which i want to ask user for an input. but i ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    8

    discard characters after space

    hi, i am writing a program in c in which i want to ask user for an input. but i want to discard all the input characters that are preceding by a space. i know you can use getchar() in a while loop somehow but cant quite get it. any help is appreciated
    please help.

    thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    All the characters preceded by a space, or those that are preceding a space, or all the spaces that precede a character?

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    8
    Quote Originally Posted by tabstop View Post
    All the characters preceded by a space, or those that are preceding a space, or all the spaces that precede a character?
    All those that are preceded by a space.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So read through the characters one by one; if the one you read is a space, set a flag; if the flag is set, ignore the character and clear the flag.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of characters ending after a space
    By RichardH in forum C Programming
    Replies: 8
    Last Post: 03-28-2007, 06:11 PM
  2. Input from file no white space characters
    By Dan17 in forum C++ Programming
    Replies: 5
    Last Post: 05-09-2006, 09:28 AM
  3. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 02:00 PM
  5. extract characters to '.'
    By VanJay011379 in forum C++ Programming
    Replies: 5
    Last Post: 07-30-2002, 12:32 AM

Tags for this Thread


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