Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
void delete_record(RECORDS record[], int rows)
{
	char name[30], id[5], line[200];
	int index = -1;

	ifstream infile;
	infile.open ("StaffRecord.txt");
	ofstream temp;
	temp.open("temp.txt");

	cin.ignore();
	cout << "Please enter the name to delete : ";
	cin.getline(record[rows].staff_name, 25);
	cout << "\nPlease enter the id to delete : ";
	cin.getline(record[rows].staff_id, 5);

	while (infile)//get record in text file
	{
		infile.getline(record[++index].staff_name, 24, '\t');
		infile.getline(record[index].staff_id, 9, '\t');
		infile.getline(record[index].position, 22, '\t');
		infile.getline(record[index].IC_No, 15, '\t');
		infile.getline(record[index].date_joined, 11, '\t');
		infile.getline(record[index].address, 15, '\t');
		infile.getline(record[index].contact_no, 12, '\n');
	}

	for (int i = 0; i < rows; i++)
	{
		if (strcmp(name, record[i].staff_name) != 0 && strcmp(id, record[i].staff_id) != 0)
		{
			temp << left << setw(24) << record[i].staff_name
				<< left << setw(8) << record[i].staff_id
				<< left << setw(24) << record[i].position
				<< left << setw(16) << record[i].IC_No
				<< left << setw(16) << record[i].date_joined
				<< left << setw(16) << record[i].address
				<< left << setw(11) << record[i].contact_no << endl;
		}
	}

	temp.close();
	infile.close();
	remove("StaffRecord.txt");
	rename("temp.txt", "StaffRecord.txt");
}


What I have tried:

I have tried to use the vector but the program also keeps looping.
Posted
Updated 19-Aug-17 1:01am

1 solution

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900