how do i compare dis to a source code..??

The Database:

AF - Afghanistan
AL - Albania
PH - Philippines: Smart, Globe(country's telephone operator)
US - United States: Digicell, Movistar


The ouput must be:

Enter Country Code: PH
Philippines: Smart, Globe

pls.. give me some source code..

Recommended Answers

All 4 Replies

Is it a C or C++ program? Do you know how to open and read text files? If you do, then just read each line and compare the first two characters with the country code.

SIR... Strcmp is not a satisfyng function to perform comparing of all the lines of my database

true -- strcmp() will compare the whole line, all you want to compare are the first two characters. strncmp() will do that. If you are writing a c++ program then you can use std::string's substr() method.

char line[] = "PH - Philippines: Smart, Globe(country's telephone operator)";

if( strncmp( line, "PH",2) == 0)
{
   // found it!
}

true -- strcmp() will compare the whole line, all you want to compare are the first two characters. strncmp() will do that. If you are writing a c++ program then you can use std::string's substr() method.

char line[] = "PH - Philippines: Smart, Globe(country's telephone operator)";

if( strncmp( line, "PH",2) == 0)
{
   // found it!
}

So would a simple

if ((line[0] == 'P')  &&  (line[1] == 'H'))
{
   // found it!
}

And all the codes could be put into an array so you can use a loop to search thru them to find a match.

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.