string

This is a discussion on string within the C Programming forums, part of the General Programming Boards category; hi, how do you check to see if there is a white space b/t 2 characters? thanks in advance....

  1. #1
    Unregistered
    Guest

    string

    hi,
    how do you check to see if there is a white space b/t 2 characters? thanks in advance.

  2. #2
    Nosepicker DrakkenKorin's Avatar
    Join Date
    Nov 2001
    Posts
    407
    Search for a ' ' in the string.

    I could be wrong though. More times than not, I'm usually worng the first time.
    DrakkenKorin

    Get off my Intarweb!!!!

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're correct, except that more than just 'space' are considered 'white space'. Use something like:
    Code:
    for( x=0; string[x]; x++ )
        if( isspace( string[x] ) )
            printf("witespace at %d, ascii value of %d.", x, string[x] );
    EDIT: Edited to provide a link to 'isspace'.
    NOTE: There are numerous 'is' functions in ctype.h.

    Quzah.
    Last edited by quzah; 12-10-2001 at 03:13 PM.
    Hope is the first step on the road to disappointment.

  4. #4
    Unregistered
    Guest
    thanks, but i need to ignore white spaces in front and at the end of the string. i just need to check for spaces in between 2 valid characters.
    thanks.

  5. #5
    Nosepicker DrakkenKorin's Avatar
    Join Date
    Nov 2001
    Posts
    407
    quzah:

    In your code, you use -- isspace(string[x])

    Is this a user defined function, or is in one of the header/library files?

    Thanx
    DrakkenKorin

    Get off my Intarweb!!!!

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    DrakkenKorin:

    You can find command "isspace(string[x])" in "ctype.h" library.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    Homework?

    Use isspace or the ' ' literal in your search and choose whether or not to copy it to a temp variable. Re-copy, return.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  8. #8
    Nosepicker DrakkenKorin's Avatar
    Join Date
    Nov 2001
    Posts
    407
    Thanx Gape.

    Gonna have to play with that one.
    DrakkenKorin

    Get off my Intarweb!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 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