Nov 1, 2013 at 4:18am Nov 1, 2013 at 4:18am UTC
How can I check characters in a single string (i.e., how can I compare)?
strcmp() compares two strings; but I need say for an example:
"orange"
I want to compare the characters inside "orange"- 'o' with 'e', 'r' with 'g' and so on.
Plz help me..
Nov 1, 2013 at 5:17am Nov 1, 2013 at 5:17am UTC
You can use the comparison operators '>', '<' or '=='.
What exactly is it that you want to do after comparing?
Nov 1, 2013 at 6:38am Nov 1, 2013 at 6:38am UTC
I have to cin>> user input.
A string like, 11101001.
Inside this string I want to compare 1st bit with last bit. If matches, I say YES.
How?
Last edited on Nov 1, 2013 at 6:40am Nov 1, 2013 at 6:40am UTC
Nov 1, 2013 at 6:42am Nov 1, 2013 at 6:42am UTC
Follow
a k n's advice.
1 2 3 4 5 6
char *myBinary;
cin >> myBinary;
if ( myBinary[0] == myBinary[ strlen( myBinary ) - 1 ] ) {
std::cout << "YES" ;
}
Caveat: I'm not much conversant with cstrings so above code needs to be verified.
Last edited on Nov 1, 2013 at 6:45am Nov 1, 2013 at 6:45am UTC