Problem with strcmp()

Hi everybody,
I have problem with comparing two strings.
Here they are:
str1 = akmal str2 = abror
and here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;

void main()
{
char * str1 = "akmal";
char * str2 = "abror";

if(strcmp(str1,str2))
cout << "akmal>abror\n";
else
cout << "akmal<abror\n";
} 


This code compiling and runing without any errors.
But i don't understand the result of this code.
Because i think that abror>akmal
but program gives another result.
Please help, what is correct?
strcmp(a,b)==0 //a==b
strcmp(a,b)<0 //a<b (when in ascendant order)
strcmp(a,b)>0 //a>b (when in ascendant order)
Last edited on
abror should be less than akmal because 'b' is less than 'k' in ASCII table.
But the condition is faulty anyway.
He's only verifying that they're different, not that they're in any order.
Thanks much helios.
I do it my function works.
It's true that akmal>abror.
Topic archived. No new replies allowed.