hi eveyone
i need to edit person name or Appointmendescription but not date or time in my program. i can write all the records to the file and can read from the file.
and need to edit the file now. can anyone help????
thanks..

void writeAppointmenRecords( )
{
	int index;
		//create and open an output text file

       ofstream outfile("C:\\AppointmenRecords.txt",ios::out | ios::app);
	   // Check if file is opened
            if(!outfile)          //return true if file is not opened
	  {  cout<<"\nFailed to open file!!!!\n";
         cout<<"\nPress any key to proceed ";
		 cin.get();        //read a character         
	  }
		
	for (index=0; index<currentSize; index++)
	{
        outfile<<AppointmenList[index].name<<endl;
		outfile<<AppointmenList[index].description<<endl;
		outfile<<AppointmenList[index].time<<endl;
		outfile<<AppointmenList[index].appdate.day<<" ";
		outfile<<AppointmenList[index].appdate.mounth<<" ";
		outfile<<AppointmenList[index].appdate.year<<endl;
	}  
     //write records to the file.
		outfile.close( );    // close file
		cout<<"\n\nRecord(s) has been written to the file successfully!!!"<<endl;
		cin.get();
}

void readAppointmenRecords( )
{  
	//create a stream and open the file 'AppointmenRecords.txt' for input

	 ifstream infile("C:\\AppointmenRecords.txt", ios::in);
		// check if file is opened
		  if(!infile)          //return true if file is not opened
	  {  cout<<"\nFailed to open file!!!!\n";
	                            //indicate program failed
	  cin.get();
	  }
		  while (!infile.eof())    //eof( ) End Of File function. Returns false if end file reached
       {
		infile>>AppointmenList[currentSize].name;
		infile>>AppointmenList[currentSize].description;
		infile>>AppointmenList[currentSize].time;
		infile>>AppointmenList[currentSize].appdate.day;
		infile>>AppointmenList[currentSize].appdate.mounth;
		infile>>AppointmenList[currentSize].appdate.year;
		currentSize+=1;
        }
    infile.close( ); // close file
	currentSize = currentSize -1;
	cout<<"\n\nRecords has been read from the file successfully!!!"<<endl;
	cin.get();
    
}
void editAppointmenRecords( )
{
	int editname;
	system("cls");  //clear screen
	cout<<"\nEnter person Name you want to Edit: ";
	cin>>editname;
	ifstream edfile("C:\\AppointmenRecords.txt");
	if(!edfile)          //return true if file is not opened
	  {  cout<<"\nFailed to open file!!!!\n";       //indicate program failed
		 cin.get();                       
	  }
}

Well, A simple solution would be to read in all the data. Find the person whose data needs to be edited. Then after that. Edit the data.
Then Write the file all over again .

can you give me any exaples???

void editAppointmenRecords( )
{
	int editname;
	system("cls");  //clear screen
	cout<<"\nEnter person Name you want to Edit: ";
	cin>>editname;
	ifstream edfile("C:\\AppointmenRecords.txt");
	if(!edfile)          //return true if file is not opened
	  {  cout<<"\nFailed to open file!!!!\n";       //indicate program failed
		 cin.get();           
            readAppointmenRecords( );
for (for (int a=0; index<currentSize; a++)
{
if(editname==AppointmenList[a].name)
{
//Provide Edit Options here
}
break;
}
void writeAppointmenRecords( );

}
	  }

}

I guess something like that.

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.