my code so far......
// ProjectDevelopment.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream> // This libary allows standard input and output operations.
#include <string> // strings are used as tempory storage - for the input to a text based file
#include <vector> // at one point in my program i expermented with vectors for data storage
using namespace std; // (or maybe std::getline;, std:: string;, std:: cout; , std:: cin; (namespace howecver is a short hand version to reduce code and possible errors.
#include <fstream> // this allows filestreaming and allows the reading and writing of a file
#include <iomanip>
#include <cstring>
int intEnterANumber;
int intConfirmation;
ifstream in ( "Store" );
string temp;
string strConfirmation;
string strFirstName;
string strSurname;
string strMiddleName;
string strNickName;
string strTelephoneNo;
string strMobileNo;
string strHouseNo;
string strRoadStreet;
string strVillageTown;
string strPostcode;
int AddFirstName(int intEnterANumber)
{
cout << "Please Enter the FirstName \n";
cin >> strFirstName;
ofstream File;
File.open("Store.txt",ios::app);
File << strFirstName;
File <<",";
File.close();
return 0;
}
int AddSurname(int intEnterANumber)
{
cout << "Please Enter the Surname \n";
cin >> strSurname;
ofstream File;
File.open("Store.txt",ios::app);
File << strSurname;
File <<",";
File.close();
return 0;
}
int AddMiddleName(int intEnterANumber)
{
cout << "Please Enter the Middle Name\n";
cin >> strMiddleName;
ofstream File;
File.open("Store.txt",ios::app);
File << strMiddleName;
File <<",";
File.close();
return 0;
}
int AddTelephoneNo(int intEnterANumber)
{
cout <<"Please Enter a Telephone Number\n";
cin >> strTelephoneNo;
ofstream File;
File.open("Store.txt",ios::app);
File << strTelephoneNo;
File <<",";
File.close();
return 0;
}
int AddAddress(int intEnterANumber) // a function which is called by the switch statement.
{
cout <<"Please Enter the House No\n";
cin >> strHouseNo;
ofstream File;
File.open("Store.txt",ios::app);
File << strHouseNo;
File <<",";
File.close();
cout <<"Please Enter the road or street name\n"; // use street(ST) or (R) for road or street check validation.
cin >> strRoadStreet;
File.open("Store.txt",ios::app);
File << strRoadStreet;
File <<",";
File.close();
cout <<"Please Enter the Village or town name\n"; // use Village or (VI)or Town (T) for validation check on town or street
cin >> strVillageTown;
File.open("Store.txt",ios::app);
File << strVillageTown;
File <<",";
File.close();
cout <<"Please Enter the Postcode\n";
cin >> strPostcode; // Check length during validation. With country as well we could have allowed selection of zipcodes etc.
File.open("Store.txt",ios::app);
File << strPostcode;
File <<",";
File <<"\n";
File.close();
return 0;
}
int main(int argc, char *argv[]) // could just be just int main
{
do {
int intEnterANumber;
cout << "Welcome To Your Phone \n\n";
cout << " (1) Enter a New Person's Details \n";
cout << " (2) Enter a New Person FirstName and telephone No. \n";
cout << " (3) Search Phone Book for all Names \n";
cout << " (4) Search Phone Book by Firstname n\n";
cout << " (5) Exit \n\n";
cout << "Please Select A Number From the Options Above\n ";
cin >> intEnterANumber;
switch (intEnterANumber)
{
case 1: AddFirstName(intEnterANumber);
AddMiddleName(intEnterANumber);
AddSurname(intEnterANumber);
AddTelephoneNo(intEnterANumber);
AddAddress(intEnterANumber);
break;
case 2: AddFirstName(intEnterANumber);
AddTelephoneNo(intEnterANumber);
break;
//case 3:
//if(!in){
// cout << "Cannot open file.";
// exit (1);
//}
//char str[255];
//while(in){
//in.getline(str, 255);
//cout << str << endl;
//}
// in.close();
//} break;
case 4:
//bits of code not quite right
char* strSearchData;
cout << "Please enter a name for searching \n";
cin >> strSearchData,255 ;
in.open("Store.txt");
char* strDataStore;
while ( in.getline( strDataStore, 50));
// tried to write token to seperate words in text file (creating split).
//using commors.
strcmp (strDataStore,strSearchData );
// sought of works cause error on intilzation.
{ // Planning to use if strcmp is true do below if false do other)
cout << strDataStore <<endl;
in.close();
} break;
}
// case 5:
// exit(EXIT_SUCCESS)
// or
// exit(1)
}
while (intEnterANumber !=6 );
return 0;
}
if you notice under case 4 - there is a an attempt at some rather bad search code. please help me make my file searchable. i have tried so many different ideas like linear search. but nothing is working. note strcmp and strcpy is a must. please point me in the right direction if you read this code.
many thanks to those who help me - no need to rush.
sincerly stephen.a.barratt - posted name to show it is my coding.