0

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..

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by WaltP
0

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.

0

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

0

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!
}
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.