Alrighty

I believe this is my last issue with this assignment I will need the forums help with "Yay!"

I have two more function to write/complete for this program.

I have to take in 4 peices of data in my add record function, Course Code, Subject Description, mark 1 and mark 2. They have to appeare in the text file as follows

CourseCODE
Subject
Mark1
Mark2

I have my add function checking the file before it writes to make sure this not a duplicate course alredy there.

In my delete and change funcitons I use this procedure to check to make sure the coursecode is the file before I attempt to delete it.

my understanding of how the delete is to work, is that I create a temp file (no problem there) and copy the contents of my data file except the "deleted" records to the temp file, then delete the old data file and rename the temp one to that of the deleted file.

I am not sure how to read from file and write to another while simultaniously avoiding the four fields in the record once I find the record to be deleted or modified.

so say I select to delete COMP086 from the text file that looks like this
Code:
COMP059
Hardware Fun
89.99
70.10
COMP086
Programming in C
98.99
89.99
COMP098
Intro to Microprocessors
67.00
76.89
I can Identify the the field exisits but I am not sure where to go from there. here is my code for this function as it sits now

Code:
int delSubject()
{
	//declare local variables
	int j = 0;
	int duplicate = 0;
	char courseCODE[8];
	char buff[BUFSIZ];
	char *p;
	FILE *fp;
	FILE *tp;

	// Get course code from user
	fp = fopen(MarkFile, "r");
	do
	{
		duplicate = 0;	
		system ("cls");
		printf("\n\n	Class Mark Subject Management \n\n");
		printf("		** Delete Subject ** \n\n");
		printf("		Please enter the 7 digit course code \n");
		printf("\n	Please press <Enter> to continue ");
		getchar();
		fgets(buff, sizeof buff, stdin);
		sscanf(buff, "%7s", courseCODE);

		// Check course code for alpha chars and convert them to upper case
		for(j=0; j<=7; j++)
		{
			if(isalpha(courseCODE[j]))
			{
				courseCODE[j]=toupper(courseCODE[j]);
			}
		}

		//compare input course code to those already on record for matching record

		//Loop through the data to check the fields
		while (fgets(buff, sizeof(buff), fp))
		{
			if ((p = strchr(buff, '\n')) != NULL)
			{
				*p = '\0';
			}
			if (strcmp(courseCODE, buff) != 0)
			{
				duplicate = 1;
				system ("cls");
				printf("\n\n\n	Matching course code not found please enter a valid code\n\n");
				printf("	Press any key to continue.\n");
				getchar();
				break;
			}
		}
	}while (duplicate != 0);
	fclose(fp);

	printf("\n\n	Account successfully deleted press any key to continue ");
	getchar();
	getchar();

	return 0;
}

int changeMark()
{
	return 0;
}
I assume using

Code:
system("del marks.txt");
system("rename temp.txt marks.txt")
will work once I have copied the appropriate data over to the temp file.

TIA for any help

clearrtc