I have been working on this code for over 2 weeks now and it finally compiles. I am required to open a text file and validate it. It is supposed to then print the applicable errors to screen .
What I need help with is:
1. Regardless of what I type in when prompted for the disk file name in dos, it still opens the file for me. My fopen code must be wrong?
2. The only error that comes up is error 2 (@%c separator line is expected...). I have rigged the text file so as to bring up the other errors but still only that error comes up.
3. My "for loop" code doesn't seem right (for you experienced programmers you're probably laughing at it right about now). I don't see what is wrong with it but ...?
Here is the portion of my code that is applicable. I would really appreciate any suggestions.
int validate_file ( const char Bank, int D_A, int summary )
FILE * bank;
LargestMark = 1,
mark, /* difficulty level of an item */
bankOK = 1, /* no error has been found so far */
orderOK = 1, /* no out of order difficulty level is met */
end_old = 0, /* line number at which previous item ends */
end_new = 0, /* line number at which new item ends */
i; /* loop control */
char separator ; /* digit that identifies the @ separator */
/* line of a section in error, if err==2 */
clrscr () ;
bank = fopen("C\\TMA307\\itembank.txt", "r");
if (itembank == NULL)
printf("\n \n\%sError 7: Unable to open itembank file. %s \n", fopen);
if (itembank == EOF)
printf("\n\n\n\ %sError 1: Unexpected end-of-file has occurred. %s\n");
return ( 1 );
for (i=1; i!=NULL; ++i)
if(itembank > MAXITEMS)
printf("\n\n\%sError 8: The number of items in the bank . %s\n", bank, MAXITEMS)
return ( 0 );
if(separap != '@')
printf("\n\n\n\ %sError 2: @%c separator line is expected. %s\n", separap);
return ( 2 );
//...additional error codes are included here...