HOw do you compare 2 strings without using strcmp...???

would u please give me an example and how it will work..

THNK YOU Very Much!!:S:X

you could try implementing your own version of strcmp?

strcmp() maintains two pointers to char, one for the first string, one for the second - it compares the values of what the pointers point to (ie the value of the char currently being pointed to) - if this value is zero (i.e. equal) then it increments the pointers and compares the next pair of bytes.

otherwise it returns with either a positive or negative value.

as far as I know strcmp() will return positive or negative based only on the first pair of bytes.

does that help?

Of course the other way is to use STL string objects and just use the overloaded logic operators built into the class, but I don't think that's quite what your question meant.

Sir thnk you for a wonderful advice..

Ahmm.. briefly how will i operate the program correctly if the output of my program is always at the first line only of my database...

example... my problem is i will type a country code:


Enter Country Code : US (e.g.)

/* the answer will be like this.. */

United States: Digicel, Movistar and other telephone companies in that country,,


Enter Country Code: US(e.g.)

Afghanistan                 //this is always the reply of my input..


(at my database)

hmmm. it is something like this...

AF - Afghanistan
AX- Aland islands
PH - Philippines: Cure, Globe, Smart, Sun
US - United States: Digicel, Movistar etc...


my program is like this..
Hope u can help me..

using namespace std;
int main()
char code[5];
char whole[800];
cout << "\n\n\tType the Country Code: \t\t ";
cin >> code;
FILE *f;
f=fopen("countrycode.csv", "r");
if(f==NULL) cout<< "cant open";
int a=0, i;
char delimeter[]="-\"", who[800][800];
char *huj=strtok(whole, delimeter);
if(a++>=sizeof who/ sizeof *who)
huj=strtok(NULL, delimeter);
for (i=0; i<a; i++)
cout << who[1]<<endl;
{    cout << "INVALID!!!";
}    }
return 0;
commented: News just in, you're an idiot! -1

It looks like in the loop:

for( i=0; i<a; i++)
    if(strcmp(code, who[1])!= 0)
          strcmp(code, who[1]);
          cout << who[1] << endl;

might be your problem - why are you only comparing code with who[1]. If you do that, then yes you will always get "Afghanistan" as your output...
Should who[1] be who perhaps?

Can you explain a bit more what it is your attempting to do?

best wishes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.