AXAsianXie 0 Newbie Poster

Hi can someone look at this program for me it wont fill out the whole address for me and when i search or go delete it doesn't do anything.

#include<iostream.>
#include <fstream>
using namespace std;

struct Person
{
		char Name[50];
		char Address[80];
		char Phone[30];
};

void add();
void search();
void dlete();
void mygetline();

int main(){

 char option;

 cout << "Welcome to your address book please select an option below:\n";
 cout << "A = Add a new entry.\n";
 cout << "D = Delete an entry.\n";
 cout << "S = Search/View entry.\n";
 cout << "E Exit.\n";

 while(cin){    //Loop Menu
  cin >> option;
  if(option=='A'){
   add();
  }
  else if(option=='D'){
   dlete();
  }
  else if(option=='S'){
   search();
  }
  else if(option=='E'){
   exit(1);
  }
  else{
   cout << "Invalid choice! A, D, or S (exit with E):";
  }
 }
}




void mygetline(char X[]) 
{

char ch;
int i=0;
cin.get(ch);
while ( ch!= '\n'){
X[i] = ch;
i++ ;
cin.get(ch);

}

X[i] = '\0';

} 
void add( )
{
	char Name[50];
	char Address[80];
	char Phone[30];

	Person p;
	fstream op;
	op.open("addresst.txt", ios::app );
	cout << "Enter the person's name:";
	cin >> p.Name;
	mygetline(Name);  
	cin.ignore();        
	cout << "Enter the person's Address:";
	cin >> p.Address; 
	mygetline(Address);  
	cin.ignore();        
	cout <<"Enter their Phone #:";
	cin >> p.Phone;
	mygetline(Phone);   
	cin.ignore();       
	cout << "Here is this person's Name, Address and Number:\n";
	cout << "Name: " << p.Name << endl;
	cout << "Address: " << p.Address << endl;
	cout << "Phone: " << p.Phone << endl;
	op.close();
	
}


   
void search(){
	char phone[50];
	char search[50];
	ifstream op;
	op.open("addressbook.txt");
	cout << "Enter phone number: ";
	cin >> phone;
	while(!op.eof()){
		op.getline(search, 50);
		if(strcmp(phone, search)==0){
			for(int i=0; i<3; i++){
				cout << search << endl;
				op.getline(search, 50);
			}
		}
	}
}

void dlete(){
  char phone[50];
  char search[50];
  Person p;
  ifstream op;
  op.open("addressbook.txt");
  ofstream current;
  current.open("temp.txt");
  cout << "Enter phone number: ";
  cin >> phone;
  while(op.getline(search, 50)){
    if(strcmp(phone, search)==0){
      for(int i=0; i<2; i++){
        memset(search, '\n', sizeof(search));
        op.getline(search, 50);
        }
      }
      else if(!strcmp(phone, search)==0){
      current << search << '\n';
    }
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.