Thread: homework help wanted: removing multiple spaces from array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I don't like the way this was explained, maybe this is better.

    Basically you have two strings, one is the longer string that the user entered called string A, and the string with excess white space removed. Notice that you are either in a white space section or a character section when copying A to B. Find out what section you start out in, and control your logic, by testing each character to see if it is a white space character or not. While you are in the white space section, keep moving forward in A. While you are in the character section, you will copy stuff from A to B. If you need to switch from the character section to the white space section, put a space at the end of B. When you reach the end of A, end B.

    So, keep track of the current place in A and the current place in B with separate variables. In all likelihood they will be different.

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    37
    That is what I was trying to do with my i2 variable as this notes how many spaces were skipped, at least that was my intention. I understand the shorter string is my tempString and my longer, and containing spaces, is userString. What you're suggesting is instead of REMOVING the spaces, to just ADD a space to tempString then fill in characters as needed?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 08-16-2010, 10:00 AM
  2. Removing elements from an array
    By monki000 in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2010, 12:23 PM
  3. Code review
    By bennywhere in forum C Programming
    Replies: 16
    Last Post: 10-20-2009, 09:00 PM
  4. Sort array with multiple keys
    By Fab in forum C Programming
    Replies: 3
    Last Post: 10-26-2005, 12:57 AM
  5. Writing multiple values to an array
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-06-2002, 03:27 PM