Purpose of isspace??

This is a discussion on Purpose of isspace?? within the C Programming forums, part of the General Programming Boards category; My assigment was to figure out the prototype of the isspace, which I get. However, every site just states that ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    15

    Purpose of isspace??

    My assigment was to figure out the prototype of the isspace, which I get. However, every site just states that it detects if it is a space or not. When will this function ever be used in actual programming? When would one need to use isspace?

    ~Thanks for your help!

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    It's not just a space character that it detects (yes, the name they chose for the function is unfortunate). It detects whether the character you pass is whitespace (i.e. spaces, tabs, CR, LF...).

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    But in what situation would this be useful? Why would one need to detect a whitespace?

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Well if you read in a bunch of text and wanted to separate each word, you would look for the end of a word by looking for the first whitespace character right?

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Wouldn't that whitespace already be separating each word? That's what you use to separate each word in the first place: a space/tab/carriage return/etc.

    ~Sorry I know this probably sounds really simple, but I've only just finished one semester of computer science.

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by aznprincess888 View Post
    Wouldn't that whitespace already be separating each word? That's what you use to separate each word in the first place: a space/tab/carriage return/etc.
    Exactly. So don't you think that being able to identify such characters might be important?

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Quote Originally Posted by brewbuck View Post
    Exactly. So don't you think that being able to identify such characters might be important?

    No? I mean, it's already separated for you right? So I guess my question is, what's the point of identifying these whitespaces? What good would that do you?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    I mean, it's already separated for you right? So I guess my question is, what's the point of identifying these whitespaces? What good would that do you?
    How would you tell the bounaries of the words if you are reading them character by character?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by aznprincess888 View Post
    No? I mean, it's already separated for you right? So I guess my question is, what's the point of identifying these whitespaces? What good would that do you?
    Separated? Who separated it? When you look on the screen you see words because of your brain. The computer has no brain.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What if you want to find a certain word in a string of words and put it into a separate string...?

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    You read in text as a stream of data. Some of that data might represent a space, a tab, some might represent a return or a character. You don't know until you read it in and test it. When you test it, it would be something like this:
    Code:
    if (my_char == ' ' || my_char == '\n' ||my_char == '\r' ||my_char == '\t')
    {
        //is whitespace
    }
    wouldn't it be it be easier to do this?
    Code:
    if (isspace(my_char))
    {
        //is whitespace
    }
    It's the basic concept of function encapsulation. Once you understand this, you'll understand a large part of C code.

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Quote Originally Posted by cpjust View Post
    What if you want to find a certain word in a string of words and put it into a separate string...?
    And why exactly would you want to find a particular word in the string?
    (sorry, I know how frustrating this might seem to some of you, I'm just so confused!)

  13. #13
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by aznprincess888 View Post
    And why exactly would you want to find a particular word in the string?
    Why would you want to program a computer?

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    And why exactly would you want to find a particular word in the string?
    Have you ever used the search function provided by your browser, editor, or word processor?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by aznprincess888 View Post
    And why exactly would you want to find a particular word in the string?
    (sorry, I know how frustrating this might seem to some of you, I'm just so confused!)
    Well think about how you would implement something like a keyword parser for an anti-spam program. You'd look for certain words that spammers use a lot and give each word a certain score. If the total score exceeds a certain threshold, you mark the message as spam.
    So looking for particular words would be pretty useful there.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. State Manager
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 03-25-2007, 09:18 AM
  2. Purpose of Operator Overloading
    By xmltorrent in forum C++ Programming
    Replies: 11
    Last Post: 08-09-2006, 06:23 PM
  3. My purpose, what do I do?
    By jaylc185 in forum Game Programming
    Replies: 5
    Last Post: 05-25-2005, 10:15 AM
  4. Retro gaming purpose PC
    By Shadow in forum Tech Board
    Replies: 1
    Last Post: 11-08-2003, 05:09 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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