bool startsWith_n( string word ); // prototype here. Fully written method below main
int main()
{
ifstream infile;
string arr[ CAP ]; // CAPACITY is 500
int count=0; // how many strings stored in array so far
// TRY TO OPEN THE INPUT FILE "words.txt"
infile.open("words.txt", ios::in);
if ( infile.fail() )
{
cout << "Can't find words.txt. Are you sure it's in this directory? (do a dir command).\nDoes it accidentally have a .txt.txt extension?\n";
exit(0);
}
cout << count << " words stored into array from words.txt\n" ;
cout << "Now printing only those words from the array that start with letter 'n':\n";
// DO *NOT* MODIFY THIS LOOP OR ANYTING ELSE IN MAIN.
// JUST FILL IN THE startsWith_nl FUNCTION BELOW MAIN
for ( int i=0 ; i< count ; i++ )
{
if ( startsWith_n( arr[i] ) )
cout << arr[i] << "\n"; // each word on its own line
}
return 0;
}
// ================================================
// == == == Y O U F I L L I N F U N C T I O N B E L O W == == ==
// ================================================
bool startsWith_n( string word )
{
return false; // just to make it compile. you change as needed
}
The code to print from the array is already provided.
You just have to write the filter.
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.