Thread: string comparing

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    string comparing

    hi long time no c(++)


    i'm making a hangman in console
    my problem is the following:


    the user will have a word of lets say 10 letters

    char word[10]={something};// should i use " " or ' ', ' ', ?


    to think of then input a letter letter by letter
    like
    char input[0];

    how can i check if this letter he has given exists

    in the string word[10]

    thanks in advance

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Use the find method of the string class. I.e.

    find (charT c, size_type pos = 0) const;
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i tried all methods i could thiks of using the find function
    but i dont get use of it

    could u explain further

    how do i find a character

    in a string

    i.e

    char string1[6]="blabla";
    char string2;

    ???

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Sorry, your comment

    >in the string word[10]

    led me to think you were using the string class. Forget this because I see you are using char array strings.

    Try 'strchr' instead, i.e.

    char *strchr( const char *string, int c );

    This will return NULL if the value of c is not found in string.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    thanx man you've been very helpfull

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    pode,

    Consider Davros' original thought of using a 'string'. You can still access specific char's using [], if you like, since a string is nothing but a char array with more functionality.

    Might make life easier!

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  5. Comparing string contents
    By Slavakion in forum C++ Programming
    Replies: 3
    Last Post: 01-13-2004, 12:14 PM