Hello to who ever might be on at this time,
I have successfully made the delete function work and I am so close to having the change function work.
when I run the program and edit the file it all appears to work until the very end when it writes the file... well perhaps after that becuase the function preforms the dos commands to copy the file etc.
here is the error message I am getting
Code:
Run-Time Check Failure #2 - Stack around the variable 'recordUPDATE' was corrupted.
This is my "completed" function
Code:
int changeMark()
{
//declare local variables
int i = 0;
int j = 0;
int duplicate = 0;
char courseCODE[8];
char buff[BUFSIZ];
char *p;
char recordUPDATE[4][BUFSIZ];
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(" ** Modify 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]);
}
}
sscanf(courseCODE, "%7s", recordUPDATE[1]);
// Get input for subjectNAME from user
system ("cls");
printf("\n\n Class Mark Subject Management \n\n");
printf(" ** Modify Subject ** \n\n");
printf(" Please enter the subject name \n");
printf("\n Please press <Enter> to continue ");
fgets( buff, sizeof buff, stdin );
sscanf(buff, "%31s", recordUPDATE[2]);
// Get input for the firstMARK from user
system ("cls");
printf("\n\n Class Mark Subject Management \n\n");
printf(" ** Modify Subject ** \n\n");
printf(" Please enter the first mark \n");
printf("\n Please press <Enter> to continue ");
fgets(buff, sizeof buff, stdin);
sscanf(buff, "%5s", recordUPDATE[3]);
// Get input for the secondMARK from user
system ("cls");
printf("\n\n Class Mark Subject Management \n\n");
printf(" ** Modify Subject ** \n\n");
printf(" Please enter the second mark \n");
printf("\n Please press <Enter> to continue ");
fgets(buff, sizeof buff, stdin);
sscanf(buff, "%5s", recordUPDATE[4]);
//compare input course code to those already on record for duplicate or for quit condition
//Loop through the data to check the fields
tp = fopen (TempFile, "a");
while (fgets(buff, BUFSIZ, fp) != NULL)
{
i = 0;
if ((p = strchr(buff, '\n')) != NULL)
{
*p = '\0';
}
//Looking for Data to be deleted
if (strcmp(courseCODE, buff) == 0)
{
//Remove the data to be deleted from the buffer
for( i = 0; i < 4; i++ )
{
fprintf(tp, "%s\n",recordUPDATE[i]);
fgets(buff, BUFSIZ, fp);
}
}else{
fprintf(tp, "%s\n",buff);
}
}
}while (duplicate != 0);
fclose(fp);
fclose(tp);
fclose(fp);
fclose(tp);
system("del marks.txt");
system("rename temp.txt marks.txt");
printf("\n\n Course successfully modified press any key to continue ");
getchar();
return 0;
}
Thanks for any help
clearrtc