I'm not fully sure, but I think it works. So far so good when creating text file. There are no garbage values in it. I made these changes.
Code:
size = strlen(stuId);
size1 = strlen(stuName);
newSize = size + size1 + 3;
char *newLine = new char[newSize];
strcpy(newLine, stuId);
strcat(newLine, " ");
strcat(newLine, stuName);
strcat(newLine, "\n");
puts(newLine);
lineSize = strlen(newLine);
afile.write(newLine, lineSize);
Now only update shows garbage at the end of the list. Can you look at my update function and tell me what is wrong? I am assuming it's the size problem as well or perhaps the cout of stuRecord.
Code:
void updateRecord(fstream& afile, char *afileName)
{
streampos size;
afile.open(afileName, ios::in | ios::out | ios::binary | ios::ate);
size = afile.tellg();
afile.seekg(0, ios::beg);
char *stuRecord = new char [size];
afile.read(stuRecord, size);
cout << stuRecord;
afile.close();
}