tolower() returns the lower case character yes.
http://www.cplusplus.com/reference/cctype/tolower/
as for p1++ I am guessing that is either a pointer to a char array or an iterator of a string. It is probably starting at the first character then when you increment it , it points to the next character. So basically what it is doing is looping through the strings and checking each character (as a lower case) to the second one.
basically if you have CAR car it will check if c == c ,a == a , r == r.
! means not so when you do something like that you are saying not true aka false.
You could technically write
if( *p1 != true && *p2 != true );
and for your while statement
while( *p1 == true && *p2 == true );
*edit looks like the others beat me to it =p I guess I took too long typing
Another way you could write your program using strings instead of char arrays would be like this ps where I have the iterator
std::string::iterator
you could put the keyword auto instead but I wont so it's easier to understand.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <string>
int main()
{
std::string s_input_one( "" ) , s_input_two( "" );
std::cout << "Please enter a string: " << std::endl;
std::getline( std::cin , s_input_one ); //I like getline for strings
std::cout << "Please enter a string: " << std::endl;
std::getline( std::cin , s_input_two ); //You could make these into sub functions if you wanted I guess but I can't be bothered for something this simple
std::string::iterator s_it_one( s_input_one.begin() ) , s_it_two( s_input_two.begin() );
while( *s_it_one && tolower(*s_it_one) == tolower(*s_it_two) )
{
++s_it_one;
++s_it_two;
}
if( s_it_one == s_input_one.end() && !*s_it_two ) //thse are same two statements
{
std::cout << "The strings are the same with possible case differences" << std::endl;
}
else
{
std::cout << "The strings are different" << std::endl;
}
return( 0 );
}
|
*edit
I also think you should check to see if the size of the strings are the same..If they are not the same size they are obv different.