Thread: how do i compare strings

  1. #16
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87

    what?!

    Im i right to say that you need string.h to compare char objects? If it is, that solves it

  2. #17
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    It's a matter of symantics. Technically you don't need string.h (or cstring depending on your compiler) to compare single chars. You do need string.h (or cstring) to compare null terminated char arrays (aka, c_style strings). If you consider a single char to be a char object then you don't need string.h. If you consider c_style string to be char objects you do. I know it's picky, but that's a large part of learning the language. Better to think of single char vs c_style string as opposed to char object. The latter is too vague, string is vague enough!!!!!

  3. #18
    Unregistered
    Guest

    Here's a little help

    Instead of using an else statement to check for illegal statements try this. By the way, this is only a piece of code.


    int checker=0;
    char yorn;

    while(checker=0)
    {
    cout<<"Choose y or n and input in lowercase";
    cin>>yorn;
    if(yorn="y")
    {
    checker=1;
    //do some other stuff
    }
    if (yorn="n")
    {
    checker=1;
    //do some other stuff
    }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compare strings problem
    By chelito19 in forum C Programming
    Replies: 2
    Last Post: 04-16-2009, 08:01 PM
  2. how do i compare first letters in two strings?
    By MalickT in forum C Programming
    Replies: 8
    Last Post: 04-20-2008, 05:47 PM
  3. compare strings not working
    By gtriarhos in forum C Programming
    Replies: 7
    Last Post: 09-29-2005, 12:51 PM
  4. Trying to compare to strings...
    By imortal in forum C++ Programming
    Replies: 9
    Last Post: 05-16-2003, 12:27 PM
  5. using Stacks & Queues to compare Strings
    By eskimo083 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2003, 05:03 PM