Thread: Get rid of spaces

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

    Get rid of spaces

    if i have a string of unkown length.
    like: ".....name Bloor Danforth , stops 32, kilometers 26.3...."
    I have to get rid of spaces before and after the coma ' , '.
    The contents of the string are unknown.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Since you can't remove arbitrary array elements, you need move everything past the element you want to erase. memmove() is good for doing this.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    Quote Originally Posted by bithub View Post
    Since you can't remove arbitrary array elements, you need move everything past the element you want to erase. memmove() is good for doing this.
    but i have no idea where the coma occurs.. so how would i do it?

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well, as a good starting point look in your C library documentation and see if there's anything that will locate one character in a string (hint: yes there is) then figure out how that might be used to mark the string for other functions like memmove() etc.

    The operative skill here is "looking stuff up"...

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    lol true but the string has unknown number of columns and i have to get rid of the space before and after the columns (only if the space exists)

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by wasi.cjr View Post
    lol true but the string has unknown number of columns and i have to get rid of the space before and after the columns (only if the space exists)
    Nobody here is going to write the code for you...

    Ok... examine the problem...
    break it down to it's smaller parts...
    what do you need to do first?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII File Copy Problem: Expand tabs to multiple spaces
    By matrixx333 in forum C Programming
    Replies: 5
    Last Post: 10-21-2009, 03:13 AM
  2. Getting rid of spaces in C
    By Poincare in forum C Programming
    Replies: 2
    Last Post: 01-23-2009, 03:08 PM
  3. Changing 3 spaces to tabs
    By dnguyen1022 in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 12:51 AM
  4. Getting rid of spaces in a string
    By David101 in forum C Programming
    Replies: 38
    Last Post: 09-23-2004, 09:01 PM
  5. Getting rid of spaces in a string
    By scythe in forum C Programming
    Replies: 3
    Last Post: 10-23-2003, 04:05 AM

Tags for this Thread