Thread: Really quick silly question.

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    21

    Really quick silly question.

    How do I parse a "?

    For example, I'm supposed to be coding a web crawler for this homework, and hyperlinks are enclosed in quotes. How do I do a

    Code:
    string word;
    //code to fill in word
    
    if (word[i] == "\"") {
    //do stuff
    I'm getting a warning about converting between integers and pointers :\

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    word[i] is one char - it should be compared to one char '\"' and not a string
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Double quotes -> string.
    Single quotes -> char.
    Strings must be compared using strcmp.
    Chars can be compared using regular comparison (==).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Strings must be compared using strcmp
    C-strings must be compared using strcmp
    std::strings should be compared using ==
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Fair enough.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Thanks, ' instead of " worked perfectly.

    Another question ><. How to easily transform strings into lowercase? I hear theres a function StringToLower, but I cant seem to get my program to recognize it. I also try word[i].tolower(), but its also recognized. Halp plz? Thanks ^_^.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    std::tolower.
    Member functions are only available on classes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Hrm, I'm missing something here. Its probably a preprocessor directive but the ones I'm finding on google arent doing me any good.

    I have:

    Code:
    string word = "Blah";
    word = tolower(word);
    Yet I receive a no matching function, candidates are INT tolower(INT).

    So how do I do this for strings @_@?

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ah, it's only for characters... Hmm.
    The Standard Library really does not shine when it comes to this... And MSDN's docs sucks on the matter.
    Well, someone else should know.
    Last edited by Elysia; 04-03-2008 at 04:47 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Just loop through the word such as;
    Code:
               for (int a=0; a<word.length(); ++a)
                word[a]=tolower(word[a]);

  11. #11
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Oh right, now that you told me how to use it, I can go back to my old loop. lol

    Thanks guys!

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is this the quality of the standard library? Not even a function to make a lower case strings?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Elysia View Post
    Is this the quality of the standard library? Not even a function to make a lower case strings?
    Code:
    transform(source.begin(), source.end(), target.begin(),static_cast< int(*)(int) >(tolower));
    The STL was made to be generic. A single function just to transform strings to lower would be too specific. This unfortunately looks a little bad with the cast, but it's necessary because there are two tolower functions.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  14. #14
    Registered User
    Join Date
    Feb 2008
    Posts
    21
    Ah ha, another questions ><. I'm trying to declare another in file stream, and its in a function outside of the main.

    Code:
    bool Crawl(blah) {
        ...
        for (int i = 0; i < hyperlinks.size(); i++) {
    	std::ifstream next_page(hyperlinks[i]);
    	if (next_page) {Crawl(web, next_page, hyperlinks[i]);}
    	next_page.close();
        }
        ...
    }
    It doesnt like this :\. No matching function calls again

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is hyperlinks a vector of std::string?

    Quote Originally Posted by King Mir View Post
    Code:
    transform(source.begin(), source.end(), target.begin(),static_cast< int(*)(int) >(tolower));
    The STL was made to be generic. A single function just to transform strings to lower would be too specific. This unfortunately looks a little bad with the cast, but it's necessary because there are two tolower functions.
    Horrible solution to a fundamental problem IMO.
    Last edited by Elysia; 04-03-2008 at 06:39 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM