Thread: stringcompare

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    3

    stringcompare

    Hello,

    I would like removing all leading and trailing blank characters from a string. I know it is possible in C++ using trim. But is it also possible in C. I am using a borland Compiler

    Thx

    Ewout Schiferli

  2. #2
    Black Mage Extraordinaire VegasSte's Avatar
    Join Date
    Oct 2002
    Posts
    167
    Will you post an example string so I can see what you mean please?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    98
    Why don't you just write your own function. It would be easy - just pass the function a string, read through it character by character, and write any non-blanks into another string. Then simply return the new string...

    It should take about five lines of code (probably best if you write them yourself though)

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    3

    Exclamation

    Here's an example of the string:
    Hello world!
    How are you.
    Ok.

    These three lines I would like to save as a string like:
    Hello world! How are you. Ok.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ok, so post your code attempt and we'll help you along the way. Doubtless someone will ruin your learning experience by just posting the whole freeking answer, but in the long run, you'd be better off if we can help you understand / learn the process by showing us your attempt and any errors you're getting.

    It's fairly basic:

    1) while this letter is a space, skip ahead one letter.
    2) while this letter is not a space, copy this letter someplace
    3) copy one space to someplace
    4) without actually using the word 'goto', go to step 1 until you run out of letters.
    5) Since we're out of letters, 'someplace' should now hold our end results. Do something with it.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    3

    Smile

    Thank you

    I will start immediately

  7. #7
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    You can use the isspace function.

Popular pages Recent additions subscribe to a feed