trimming of a string

This is a discussion on trimming of a string within the C Programming forums, part of the General Programming Boards category; Can anyone of you tell me whether any function is available in C language to remove the white spaces at ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    4

    trimming of a string

    Can anyone of you tell me whether any function is available in C language to remove the white spaces at the beginning and end of a string.

    -Rangan

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    It would be very simple to write one - probably faster to write it than to search for an API containing such a function.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    well r there no API's present.. i am have a sentence and i want to just take the blank space at the beginning and end. will strtrim() work?

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    WTF is strtrim()?

    All you have to do is loop through the string from the beginning, eliminating spaces until you reach a non-space character. Then loop through the string from the end doing the same thing.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    Well thanks.,..can u explain
    #define main Main /* Now try to link this! */
    #define stdout stderr /* No problems, until you pipe it */
    #define while(x) if(x)
    #define struct union /* Great space saver */

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Please use proper English and complete sentences. I understand that communicating is difficult if English is not your first language, but most other languages do have a requirement that you use complete words, sentences, and meaningful punctuation. strtrim() is not a standard function. If you are referring to a thrid-party library, please state what library that is.

  7. #7
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
    Well thanks.,..can u explain
    #define main Main /* Now try to link this! */
    #define stdout stderr /* No problems, until you pipe it */
    #define while(x) if(x)
    #define struct union /* Great space saver */
    It is a list of preprocessor directives that can be used as pranks. By placing this in someone else's source code it will cause bugs to appear in their program logic and mask the true source of the bug. Click on the link below that list for a better explanation.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    hey buddy thanks for the reply. I just wanted to know if there is any standard function available in C language which will remove the blank spaces from the starting and ending of a sentence.

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >> I just wanted to know if...
    To clarify: no there aren't, at least not any standard ones that we can guarantee you'll have. Write your own, it'll be a useful excerise for you anyway.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    check 'isspace()' in ctype.h , you might find it usefull along with the other similar functions (isdigit() , isalpha()...etc)
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  11. #11
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    r_213, you made me sorry, this thread is becoming a bit old so here's a little boost.
    Code:
    char *remove_white_spaces(char *dest, const char* src){
        int idx_begin, idx_end;
        idx_begin = 0;
        while(src[idx_begin].....){
        ....
        }
        idx_end = ...;//initialize with the index of the last char of src
        while(src[idx_end].....){
        ....
        }
        //copy src from idx_begin to idx_end to dest
        return dest;
    }
    Now you complete the rest.
    Last edited by xErath; 11-19-2004 at 08:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21