Exforsys
+ Reply to Thread
Results 1 to 4 of 4

How to achieve this - Minimum Code to Strip Blank Spaces

This is a discussion on How to achieve this - Minimum Code to Strip Blank Spaces within the C and C++ forums, part of the Programming Talk category; Hi All, I have a string with blank space throughout the string that is at several places in between the ...

  1. #1
    norman is offline Member Array
    Join Date
    May 2006
    Answers
    43

    How to achieve this - Minimum Code to Strip Blank Spaces

    Hi All,
    I have a string with blank space throughout the string that is at several places in between the string. But I want the final output of the string with the blank spaces stripped off or removed off. How to achieve the above with minimum line of code in C program?

    Regards,
    Norman


  2. #2
    Allan is offline Member Array
    Join Date
    May 2006
    Answers
    40
    Hi,
    One way to remove space would be to use isspace() function. One can check each character whether it is isspace() and if satisfies leave that can go to the next character. If it is not satisfied you can store that character in a character array separately. After the whole string is checkd theycan print the new character array which has all the spaces removed in it. But while thinking in this line I have a related question namely what is the header file under which this isspace is placed. Somebody clarify this because this also need to be included while using isspace() function. Also let me know whether isispace can handle only single-space.

    Regards,
    Allan


  3. #3
    blenda is offline Member Array
    Join Date
    May 2006
    Answers
    36
    Hi,
    The header file under which isspace() is present is ctype.h. The use of isspace() is a interesting idea for the problem. But I think there would be more ways to handle the same problem. Can someone suggest some more ways to handle the problem?

    Regards,
    Blenda


  4. #4
    norman is offline Member Array
    Join Date
    May 2006
    Answers
    43
    Hi,
    The function isspace() can handle single space, tab, vertical tab, form feed, carriage return, or newline. The function isspace() returns non-zero if its argument has any of the space mentioned above. Otherwise isspace() returns zero.

    Regards,
    Norman


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...