Thread: Help me with a space-deleting program

  1. #16
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    It might be easier if you take the "ch2" assignment on line 33 out of the "if()". Having it there is perfectly okay, but it might make it easier for you to break it up:

    - read character and store in "ch2"
    - then use the "if()" statement to check for multiple possible values (like you did on line 29)

  2. #17
    Registered User
    Join Date
    Jan 2013
    Posts
    7
    Quote Originally Posted by Matticus View Post
    It might be easier if you take the "ch2" assignment on line 33 out of the "if()". Having it there is perfectly okay, but it might make it easier for you to break it up:

    - read character and store in "ch2"
    - then use the "if()" statement to check for multiple possible values (like you did on line 29)
    Done. But I think reading two chars approach is kinda lame if you're going to remove several spaces/newlines, that worked for single ones.
    Am I wrong?
    Last edited by n00b5ter; 01-10-2013 at 02:48 PM.

  3. #18
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    After reading one character from the source you have three different cases:

    • The character is ' ' or '\n': Add the character to a temporary buffer
    • The character is ',' or '.': Add the character to the destination and clear the buffer.
    • Any other character: Add the buffer to the destination, add the character and clear the buffer.


    I can't think of a solution without a temporary buffer which handles cases like
    Code:
    foo   \n   \n   bar    ->  foo   \n   \n   bar (no changes)
    foo   \n   \n   ,bar   ->  foo,bar
    i.e. where you have mixed spaces and newlines before any other character.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deleting a program
    By 182 in forum C++ Programming
    Replies: 5
    Last Post: 02-23-2006, 09:10 PM
  2. a space in a program path
    By eam in forum C Programming
    Replies: 2
    Last Post: 10-26-2003, 10:19 PM
  3. Deleting a file while in a program
    By Blizzarddog in forum C++ Programming
    Replies: 1
    Last Post: 07-17-2003, 12:01 PM
  4. deleting a space from a string
    By niroopan in forum C++ Programming
    Replies: 4
    Last Post: 01-10-2003, 09:43 PM
  5. Disappointed in the Space Program
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 11-26-2002, 06:26 AM

Tags for this Thread