I haven't been on the forums for over like 20 days because I have been busy with things, and then my internet died. Not that anyone cared, but I'm just saying this so Vmane won't think that I just copied his code solution and ran away if he stumbled upon this thread o_O;
Anyways, I have an old assignment in class that I have to put some finishing touches on to be submitted, and there are two small things (well 3) that I have no idea how to fix or change. Basically, the program is the same as the store products one that I asked a long time ago (look in my post history), but this one is slightly more expanded with update and search functions.
These are my concerns with the project:
1] I don't know why this is happening, but when I enter data to be stored in the wordpad file, it randomly comes out fine and sometimes it displays as weird characters. Here is a picture included:
http://img505.imageshack.us/img505/1097/helpttcu0.png
I don't see anything wrong with my source code from what I can tell, and what's weird is that it worked when I entered in data the first time, but when I completely erased the file and started a new one, the display screen started showing weird characters.
*************
2] Is it possible to only display a certain part of the string when reading from a file? We have learned about concatenating and copying strings, but I don't know if it is possible to read only 5 characters from one string and display it? That also raises more concerns I think, as what if the string isn't the specified length? Would I have to make an automatic FOR loop and check the amount of characters in the string, and then copy a ratio of it or something?
*************
3] In the last part of my program, I kind of got stuck when comparing strings. What I'm trying to do here is to copy the string from the file, paste it into a temporary file, and then compare it with the entered string from the user (to search). As far as I can tell, using string compare that way is correct, but no matter what I enter or how I modify the strings, a match is never found?
I realize that my program is approximately 20%-40% copied from an example in class at this point (the product assignment), but I lack the knowledge to do what I wanted earlier due to time constraints (make two files, storing private data in one, and then that file reads from another one and gets the rest of the data).
Anywho, can anyone help me or guide me in the right direction with the above questions? I'll try to improve my C++ skills, but I'm kind of busy with all sorts of essays at the moment O_O;
P.S. Is it good form to use the goto ___ command instead of a do loop? I find it easier than one and much less complicated with braces.
// Viet Phan
// Real Assignment #5
// April 22nd, 2008
#include "main2.h"
void main()
{
// Setting Graphics
init_graphics();
int choice1;
menu:
// Title
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (27,2);
cout<< "Canadian Geographic Database";
cout.flush();
set_cursor_pos (29,3);
set_color (cBLUE,cBLACK);
cout<< "Please select an option.";
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (23,5);
cout<< "*---------------------------------*";
cout.flush();
set_cursor_pos (23,6);
cout<< "|1. Add Provinces/Territories|";
cout.flush();
set_cursor_pos (23,7);
cout<< "|2. List Provinces/Territories|";
cout.flush();
set_cursor_pos (23,8);
cout<< "|3. Update Provinces/Territories|";
cout.flush();
set_cursor_pos (23,9);
cout<< "|4. Search Provinces/Territories|";
cout.flush();
set_cursor_pos (23,10);
cout<< "|5. Exit |";
cout.flush();
set_cursor_pos (23,11);
cout<< "*---------------------------------*";
cout.flush();
set_color (cRED,cBLACK);
set_cursor_pos (27,12);
cout<< "Please enter your choice: ";
cout.flush();
// Get 1 char only for choice
choice1= cin.get();
cin.width (2);
cin.ignore (50, '\n');
switch (choice1)
{
case '1':
add_province();
break;
case '2':
list_province();
break;
case '3':
update_province();
break;
case '4':
search_province();
break;
case '5':
set_color (cWHITE,cBLACK);
set_cursor_pos (27,15);
cout<< "Exiting...";
cout.flush();
set_cursor_pos (27,16);
wait (2000);
return;
default:
set_color (cMAGENTA,cBLACK);
set_cursor_pos (28,15);
cout<< "Invalid Choice, Try Again.";
cout.flush();
wait (2000);
break;
}
// Return to menu
goto menu;
return;
}
//***********************************************************************************************
void add_province()
{
prov prov;
fstream outsave;
char choice2;
int lengthprov;
int lengthcap;
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (33,2);
cout<< "Adding a Province\n--------------------------------------------------------------------------------";
cout.flush();
set_color (cRED,cBLACK);
set_cursor_pos (8,5);
cout<< "Fill out the following information: ";
cout.flush();
// Getting Province Name
set_color (cWHITE,cBLACK);
set_cursor_pos (10,7);
cout<< "Province Name: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.province, 30, '\n');
cin.width (30);
_strlwr (prov.province);
if (prov.province[0] <96 || prov.province[0] >123)
{
prov.province[0]-=32;
}
// Getting Capital City Name
set_color (cWHITE,cBLACK);
set_cursor_pos (10,9);
cout<< "Capital City: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.capital, 30, '\n');
cin.width (30);
_strlwr (prov.capital);
if (prov.capital[0]< 96 || prov.capital[0]> 123)
{
prov.capital[0]-=32;
}
// Getting Premier Name
set_color (cWHITE,cBLACK);
set_cursor_pos (10,11);
cout<< "Premier: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.premier, 30, '\n');
cin.width (30);
_strlwr (prov.premier);
if (prov.premier[0]<96 || prov.premier[0]> 123)
{
prov.premier[0]-=32;
}
// Getting Population Province
bool ok;
do
{
// Getting the user to input at the start of loop
set_color (cWHITE,cBLACK);
set_cursor_pos (10,13);
cout<< "Population (Province): ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.popprovince, 20, '\n');
cin.width (20);
// Finding length of string
lengthprov= strlen(prov.popprovince);
// If the value entered fails somehow, ignores everything after enter
if (cin.fail())
{
cin.clear();
cin.ignore(50, '\n');
}
ok= true;
for (int i=0; i<lengthprov; i++)
{
// Trying to compare without ASCII charts
if (prov.popprovince[i]< '0' || prov.popprovince[i]> '9')
{
ok= false;
}
}
} while (ok=false);
// Getting Population of Capital
bool ok2;
do
{
// Getting the user to input at the start of loop
set_color (cWHITE,cBLACK);
set_cursor_pos (10,15);
cout<< "Population (Capital): ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.popcapital, 20, '\n');
cin.width (20);
// Finding length of string
lengthcap= strlen(prov.popcapital);
// If the value entered fails somehow, ignores everything after enter
if (cin.fail())
{
cin.clear();
cin.ignore(50, '\n');
}
ok2= true;
for (int i=0; i<lengthcap; i++)
{
// Trying to compare without ASCII charts
if (prov.popcapital[i]< '0' || prov.popcapital[i]> '9')
{
ok2= false;
}
}
} while (ok2=false);
set_cursor_pos (8,17);
set_color (cWHITE,cBLACK);
cout<< "Processing Data...";
cout.flush();
wait (1500);
// Redisplaying all of the Data
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (33,2);
cout<< "Adding a Province\n--------------------------------------------------------------------------------";
cout.flush();
set_color (cRED,cBLACK);
set_cursor_pos (10,4);
cout<< "Information Entered: ";
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,6);
cout<< "Province: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.province;
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,8);
cout<< "Capital: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.capital;
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,10);
cout<< "Premier: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.premier;
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,12);
cout<< "Population of Province: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popprovince;
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,14);
cout<< "Population of Capital: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popcapital;
cout.flush();
set_color (cRED,cBLACK);
set_cursor_pos (10,16);
cout<< "Save the information (y/n)? ";
cout.flush();
cin>> choice2;
cin.ignore (50, '\n');
// If anything other then yes entered, exit
if (choice2!= 'y' && choice2!= 'Y')
{
set_cursor_pos (10,17);
set_color (cMAGENTA,cBLACK);
cout<< "Invalid Key Entered, Returning to Main Menu...";
cout.flush();
wait (1500);
return;
}
// Opens the file, if it is open, exit
outsave.open ("Province_Tracker.txt", ios::out | ios::app | ios::binary);
if (!outsave)
{
set_cursor_pos (10,18);
set_color (cMAGENTA,cBLACK);
cout<< "***FILE ERROR***\n";
cout.flush();
wait (1500);
return;
}
// Write to the file now
outsave.write ((char *) &prov, sizeof (prov));
set_cursor_pos (10,18);
set_color (cRED,cBLACK);
cout<< "Data Saved, Returning to Main Menu";
cout.flush();
wait (1000);
outsave.close();
cin.clear();
return;
}
//***********************************************************************************************
void list_province()
{
fstream indisplay;
prov prov;
char yes;
char prompt;
int counting=0;
int count=0;
int list=0;
clear_screen();
set_cursor_pos (27,2);
set_color (cCYAN,cBLACK);
cout<< "Displaying Province Information";
cout.flush();
indisplay.open ("Province_Tracker.txt", ios::in | ios::binary);
if (!indisplay.is_open())
{
set_cursor_pos (8,4);
set_color (cMAGENTA,cBLACK);
cout<< "The File Does Not Exist...";
cout.flush();
wait (2000);
return;
}
set_color (cBLUE,cBLACK);
set_cursor_pos (2,4);
cout<< "------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,6);
cout<< "------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,5);
cout<< "|Province|";
cout.flush();
set_cursor_pos (16,5);
cout<< "|Capital City|";
cout.flush();
set_cursor_pos (35,5);
cout<< "|Premier|";
cout.flush();
set_cursor_pos (49,5);
cout<< "|Population|";
cout.flush();
set_cursor_pos (66,5);
cout<< "|C.Population|";
cout.flush();
while (!indisplay.eof())
{
indisplay.read ((char *) &prov, sizeof (prov));
if (indisplay.eof())
{
break;
}
counting++;
count++;
list++;
set_color (cWHITE,cBLACK);
set_cursor_pos (1,7+counting);
cout<< list<< " "<< prov.province;
cout.flush();
set_cursor_pos (17,7+counting);
cout<< prov.capital;
cout.flush();
set_cursor_pos (36,7+counting);
cout<< prov.premier;
cout.flush();
set_cursor_pos (50,7+counting);
cout<< prov.popprovince;
cout.flush();
set_cursor_pos (67,7+counting);
cout<< prov.popcapital;
cout.flush();
if (counting==12)
{
set_cursor_pos (21,15);
set_color (cRED,cBLACK);
cout<< "Would you like to display more files? ";
cout.flush();
yes= getche();
if (yes== 'y' || yes== 'Y')
{
counting=0;
count=0;
clear_screen();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,7+counting);
cout<< list<< ". "<< prov.province;
cout.flush();
set_cursor_pos (16,7+counting);
cout<< prov.capital;
cout.flush();
set_cursor_pos (35,7+counting);
cout<< prov.premier;
cout.flush();
set_cursor_pos (49,7+counting);
cout<< prov.popprovince;
cout.flush();
set_cursor_pos (66,7+counting);
cout<< prov.popcapital;
cout.flush();
}
else
{
set_cursor_pos (23,22);
set_color (cMAGENTA,cBLACK);
cout<< "Invalid Key Entered, Exiting...";
cout.flush();
return;
}
}
};
set_cursor_pos (23,22);
set_color (cRED,cBLACK);
cout<< "End of File, Press Any Key to Continue";
cout.flush();
indisplay.close();
prompt= getche();
return;
}
//***********************************************************************************************
void update_province()
{
fstream inout;
fstream outfile;
streampos fileposition;
streamoff fileoffset;
prov prov;
int numcount;
int flength, recs;
int recno;
char buff[50];
int choice;
clear_screen();
inout.open ("Province_Tracker.txt", ios::in | ios::out | ios::binary);
// Check if file not open, return to main menu
if (!inout)
{
set_cursor_pos (10,5);
set_color (cMAGENTA,cBLACK);
cout<< "The File Does Not Exist...";
cout.flush();
wait (2000);
return;
}
// Check for number of records stored
fileoffset= 0;
inout.seekg (fileoffset, ios::end);
// Count the number of bytes in the file
flength= inout.tellg(); // tellg gives byte location of get pointer
if (flength==0)
{
set_cursor_pos (10,5);
set_color (cMAGENTA,cBLACK);
cout<< "No Data Stored in the File";
cout.flush();
wait (2000);
return;
}
// Calculaing the number of records
recs= flength/sizeof (prov);
clear_screen();
set_cursor_pos (33,1);
set_color (cCYAN,cBLACK);
cout<< "Update Provinces\n--------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (24,4);
set_color (cWHITE,cBLACK);
cout<< "There are ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< ""<< recs;
cout.flush();
set_color (cWHITE,cBLACK);
cout<< " entries in the file.";
cout.flush();
set_cursor_pos (22,6);
cout<< "Please choose a file to update";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< "(1-"<< recs<< "): ";
cout.flush();
cin.getline (buff, 10);
if (buff[0]< '0' || buff[0]> '9')
{
set_cursor_pos (25,8);
set_color (cMAGENTA,cBLACK);
cout<< "Invalid Value Entered, Returning...";
cout.flush();
wait (1000);
return;
}
// Get character data
if (cin.fail()) // Fail if more than 10char entered
{
cin.ignore (100);
cin.clear();
}
recno= atoi(buff); // Convert characters to numbers
// Find the file location by using lines
fileposition= sizeof (prov)*(recno-1); // Find out where the portion starts (of the file requested)
inout.seekg (fileposition);
// Reading requested file portion
inout.read ((char *) &prov, sizeof (prov));
set_cursor_pos (35,9);
set_color (cRED,cBLACK);
cout<< "Loading...";
cout.flush();
wait(1000);
display:
// ------ Now displaying all the information read from that section -----
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Update a Province\n--------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,4);
set_color (cWHITE,cBLACK);
cout<< "1. Province: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.province;
cout.flush();
set_cursor_pos (2,6);
set_color (cWHITE,cBLACK);
cout<< "2. Capital: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.capital;
cout.flush();
set_cursor_pos (2,8);
set_color (cWHITE,cBLACK);
cout<< "3. Premier: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.premier;
cout.flush();
set_cursor_pos (2,10);
set_color (cWHITE,cBLACK);
cout<< "4. Population: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popprovince;
cout.flush();
set_cursor_pos (2,12);
set_color (cWHITE,cBLACK);
cout<< "5. Capital Population: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popcapital;
cout.flush();
set_cursor_pos (2,14);
set_color (cWHITE,cBLACK);
cout<< "Press 6 to exit.";
cout.flush();
set_cursor_pos (2,16);
cout<< "Press 7 to save changes.";
cout.flush();
set_cursor_pos (2,18);
set_color (cRED,cBLACK);
cout<< "Which item do you want to update? (1-5)";
cout.flush();
set_cursor_pos (42,18);
choice= cin.get();
cin.width (2);
cin.ignore (50, '\n');
switch (choice)
{
case '1':
prov= update_provincename (prov);
break;
case '2':
prov= update_capital (prov);
break;
case '3':
prov = update_premier (prov);
break;
case '4':
prov = update_provincepop (prov);
break;
case '5':
prov = update_capitalpop (prov);
break;
case '6':
set_cursor_pos (2,20);
set_color (cWHITE,cBLACK);
cout<< "Exiting...";
cout.flush();
wait (2000);
return;
case '7':
set_color (cGREEN,cBLACK);
set_cursor_pos (2,20);
cout<< "Saving...";
cout.flush();
wait (500);
inout.seekp(fileposition);
inout.write((char*)& prov, sizeof(prov));
inout.close();
break;
default:
set_cursor_pos(2,20);
set_color (cMAGENTA,cBLACK);
cout<< "Invalid Value Entered";
cout.flush();
wait (2000);
return;
}
numcount= 0;
goto display;
return;
}
//***********************************************************************************************
prov update_provincename (prov prov)
{
// Changing the Province Name
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Change Province Name\n--------------------------------------------------------------------------------";
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,4);
cout<< "The original name was: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.province;
cout.flush();
set_cursor_pos (2,6);
set_color (cRED,cBLACK);
cout<< "Please enter the new name: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.province, 30);
if (prov.province[0]> 96 && prov.province[0]< 123)
{
prov.province[0]-=32;
}
return (prov);
}
//***********************************************************************************************
prov update_capital (prov prov)
{
// Changing the Capital Name
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Change Capital Name\n--------------------------------------------------------------------------------";
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,4);
cout<< "The original name was: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.capital;
cout.flush();
set_cursor_pos (2,6);
set_color (cRED,cBLACK);
cout<< "Please enter the new name: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.capital, 30);
if (prov.capital[0]> 96 && prov.capital[0]< 123)
{
prov.capital[0]-=32;
}
return (prov);
}
//***********************************************************************************************
prov update_premier (prov prov)
{
// Changing the Premier Name
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Change Capital Name\n--------------------------------------------------------------------------------";
cout.flush();
set_color (cWHITE,cBLACK);
set_cursor_pos (2,4);
cout<< "The original name was: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.premier;
cout.flush();
set_cursor_pos (2,6);
set_color (cRED,cBLACK);
cout<< "Please enter the new name: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.premier, 30);
if (prov.premier[0]> 96 && prov.premier[0]< 123)
{
prov.premier[0]-=32;
}
return (prov);
}
//***********************************************************************************************
prov update_provincepop (prov prov)
{
int lengthprov;
// Changing the Province Population
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Change Province Population\n---------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,4);
set_color (cWHITE,cBLACK);
cout<< "The original population was: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popprovince;
cout.flush();
bool ok;
do
{
// Getting the user to input at the start of loop
set_cursor_pos (2,6);
set_color (cRED,cBLACK);
cout<< "Please enter the new population: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.popprovince, 20, '\n');
cin.width (20);
// Finding length of string
lengthprov= strlen(prov.popprovince);
// If the value entered fails somehow, ignores everything after enter
if (cin.fail())
{
cin.clear();
cin.ignore(50, '\n');
}
ok= true;
for (int i=0; i<lengthprov; i++)
{
// Trying to compare without ASCII charts
if (prov.popprovince[i]< '0' || prov.popprovince[i]> '9')
{
ok= false;
}
}
} while (ok=false);
return (prov);
}
//***********************************************************************************************
prov update_capitalpop (prov prov)
{
int lengthcap;
// Changing the Province Population
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Change Capital Population\n---------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,4);
set_color (cWHITE,cBLACK);
cout<< "The original population was: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popcapital;
cout.flush();
bool ok;
do
{
// Getting the user to input at the start of loop
set_cursor_pos (2,6);
set_color (cRED,cBLACK);
cout<< "Please enter the new population: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.getline (prov.popcapital, 20, '\n');
cin.width (20);
// Finding length of string
lengthcap= strlen(prov.popcapital);
// If the value entered fails somehow, ignores everything after enter
if (cin.fail())
{
cin.clear();
cin.ignore(50, '\n');
}
ok= true;
for (int i=0; i<lengthcap; i++)
{
// Trying to compare without ASCII charts
if (prov.popcapital[i]< '0' || prov.popcapital[i]> '9')
{
ok= false;
}
}
} while (ok=false);
return (prov);
}
//***********************************************************************************************
void search_province()
{
fstream searchout;
int choice;
menusearch:
clear_screen();
set_color (cCYAN,cBLACK);
set_cursor_pos (32,1);
cout<< "Search Provinces\n--------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,4);
set_color (cWHITE,cBLACK);
cout<< "Please choose a field to search under: ";
cout.flush();
set_cursor_pos (4,6);
set_color (cLIGHT_GRAY,cBLACK);
cout<< "1. Province";
cout.flush();
set_cursor_pos (4,8);
cout<< "2. Capital";
cout.flush();
set_cursor_pos (4,10);
cout<< "3. Premier";
cout.flush();
set_cursor_pos (4,12);
cout<< "Press 4 to exit.";
cout.flush();
set_color (cRED,cBLACK);
set_cursor_pos (2,14);
cout<< "Please enter your choice (1-5): ";
cout.flush();
choice= cin.get();
cin.width (2);
cin.ignore (50, '\n');
switch (choice)
{
case '1':
search_provname();
break;
case '5':
set_cursor_pos (2,18);
set_color (cWHITE,cBLACK);
cout<< "Returning to main menu...";
cout.flush();
wait (1000);
return;
default:
set_cursor_pos (2,18);
set_color (cMAGENTA,cBLACK);
cout<< "Invalid Choice...";
cout.flush();
wait (1000);
break;
}
goto menusearch;
return;
}
//***********************************************************************************************
void search_provname()
{
fstream searchout;
prov prov;
char provname[20];
char searchprov[20];
char choice;
clear_screen();
set_cursor_pos (30,1);
set_color (cCYAN,cBLACK);
cout<< "Search by Province Name\n--------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (5,4);
set_color (cRED,cBLACK);
cout<< "Enter Search Name: ";
cout.flush();
set_color (cGREEN,cBLACK);
cin.width(20);
cin>> searchprov;
_strlwr (searchprov);
if (cin.fail())
{
cin.ignore (20, '\n');
cin.clear();
}
searchout.open ("Province_Tracker", ios::in | ios::binary /*| ios::nocreate*/);
if (!searchout.is_open())
{
set_cursor_pos (2,6);
set_color (cRED,cBLACK);
cout<< "** File Error Upon Opening **";
cout.flush();
wait (2000);
return;
}
while (!searchout.eof())
{
searchout.read ((char *) &prov, sizeof (prov));
if (searchout.eof()) break;
strcpy (provname, prov.province);
_strlwr (provname);
if (strcmp(searchprov,provname)==0) // If two strings (not chars) are exactly same, do the statement
{
// Match Found
//
clear_screen();
set_cursor_pos (1,1);
cout<< "-------------------------------------------------------------------------------------------";
cout.flush();
set_cursor_pos (2,4);
set_color (cWHITE,cBLACK);
cout<< "1. Province: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.province;
cout.flush();
set_cursor_pos (2,6);
set_color (cWHITE,cBLACK);
cout<< "2. Capital: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.capital;
cout.flush();
set_cursor_pos (2,8);
set_color (cWHITE,cBLACK);
cout<< "3. Premier: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.premier;
cout.flush();
set_cursor_pos (2,10);
set_color (cWHITE,cBLACK);
cout<< "4. Population: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popprovince;
cout.flush();
set_cursor_pos (2,12);
set_color (cWHITE,cBLACK);
cout<< "5. Capital Population: ";
cout.flush();
set_color (cGREEN,cBLACK);
cout<< prov.popcapital;
cout.flush();
//
//
set_cursor_pos (10,11);
set_color (cRED,cBLACK);
cout<< "Press Any Key to Continue";
cout.flush();
choice= getche();
wait (2000);
searchout.close();
break;
}
}
searchout.close();
set_cursor_pos (10,6);
cout<< "No Match Found";
cout.flush();
wait (1000);
return;
}
//***********************************************************************************************
// HEADER: FIELD OF DREAMS
/* COLOUR LIST
Cyan= Title
Red= Prompt
White= Choices
Magenta= Error
Green= Update
Gray= Variables
*/
// Declaring packs
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <fstream.h>
#include "msoftcon.cpp"
// Structure for stuffz
struct prov
{
char province [30];
char capital [30];
char premier [30];
char popprovince [20];
char popcapital [20];
};
// Main Functions
void add_province();
void list_province();
void update_province();
void search_province();
// Sub Functions of search
void search_provname();
// Used to re-update parts of file
prov update_provincename (prov prov);
prov update_capital (prov prov);
prov update_premier (prov prov);
prov update_provincepop (prov prov);
prov update_capitalpop (prov prov);