Thread: discard characters after space

  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,336
    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,336
    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, 05:11 PM
  2. Input from file no white space characters
    By Dan17 in forum C++ Programming
    Replies: 5
    Last Post: 05-09-2006, 08: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, 01:00 PM

Tags for this Thread