// PhastPhind2.1.cpp // The world's fastest phone number finder, this time with a text file with the numbers in! // and the ability to type more than one part of the name, woah! #include #include #include #include using namespace std; #define FIELDLENGTH 40 int initialread(void); void read(char*, char*, char*); void mysearch(char*, char*, char*,char*,int numpeople); void concat(char*, char* , char*,int count); void lower(char *); void clean(char *); main() { int numpeople; char again; numpeople = initialread(); // this function just counts the number of lines char * firstname; char * surname; char * phone; char * listed; firstname = new char[numpeople*FIELDLENGTH]; surname = new char[numpeople*FIELDLENGTH]; phone = new char[numpeople*FIELDLENGTH]; listed = new char[numpeople]; read(firstname,surname,phone); // reads in data from text file cout << "PhastPhind2.1 By Alex Sheldon 2005 - The world's fastest phone " << "number finder.\n\n"; do { mysearch(firstname,surname,phone,listed,numpeople); // search cout << "\n\nPress any key to try again, or 'Q' to quit\n\n"; again = getch(); if(again=='Q')again='q'; } while(again != 'q'); } int initialread(void) { int count = 0; char buffer[256]; ifstream PhastList ("PhastList.txt"); if(! PhastList.is_open()) { cout << "\n\n***PhastList phone number list is missing***"; getch(); exit(1); } while(! PhastList.eof()) { PhastList.getline (buffer,256); count++; } return(count); } void read(char *firstname, char *surname, char *phone) { int count = 0; ifstream PhastList ("PhastList.txt"); while(! PhastList.eof()) { PhastList >> &firstname[(count*FIELDLENGTH)]; clean(&firstname[(count*FIELDLENGTH)]); PhastList >> &surname[(count*FIELDLENGTH)]; clean(&surname[(count*FIELDLENGTH)]); PhastList >> &phone[(count*FIELDLENGTH)]; clean(&phone[(count*FIELDLENGTH)]); count++; } } void mysearch(char *firstname, char *surname, char *phone, char *listed, int numpeople) { char searching[80], buffer[256], found = 'n'; char *psearching; int namelength, count = 0; char temp[80]; char *ptemp; ptemp = temp; // just have a go and see if just ptemp=temp works psearching = searching; // same here for(int x=0; x< numpeople;x++) listed[x] = 'n'; // make them all not listed cout << "Enter a part of the name: "; cin.getline (buffer, 256); cout << endl; if(strlen(buffer) > 80) // stops the program from crashing if a user types loads in { cout << "Search string too long! Re-start the program and stop messing around!\n\n"; getch(); exit(1); } strcpy(searching, buffer); namelength = strlen(searching); lower(psearching); clean(psearching); for (count=0; count=65 && *(text+x)<=90) *(text+x) += 32; // if capital, make lower } } void clean(char *text) { int length; length = strlen(text); for(int x=0;x