A True Canadian
Newbie
- Joined
- Aug 29, 2003
- Messages
- 2,874
- Reaction score
- 2
I have created a crude piece of code that is to take inputs from the user until they wish to exit.
I've reached a snag, and it's 12:30am over here in Canada, and I can't quite seem to get the End Of File Marker to work properly.
As with the last time, it's likely to be something trivial. I just can't see the problem now. I'll keep working on it until I do find a fix, but suggestions would be helpful.
I've reached a snag, and it's 12:30am over here in Canada, and I can't quite seem to get the End Of File Marker to work properly.
Code:
#include <stdio.h>
void main()
{
FILE *empl;
long idnum;
int i, num;
char edtype;
float salary;
empl = fopen("C:\\Documents and Settings\\MDG\\Assignment 3\\salary.txt", "w");
printf("Press any key to begin or CTRL-Z to exit");
i = scanf("%d", num);
fflush(stdin);
while (i != EOF)
{
while(!feof(empl))
{
printf("Student Number => ");
scanf("%ld", &idnum);
fflush(stdin);
printf("Education Type ('c', 'u', 'h') => ");
scanf("%c", &edtype);
fflush(stdin);
do{
if (!(edtype == 'c' || edtype == 'u' || edtype == 'h'))
{
printf("Input is invalid.\n");
scanf("%c", &edtype);
}
else
break;
} while (!(edtype == 'c' || edtype == 'u' || edtype == 'h') || EOF);
printf("Salary => ");
scanf("%f", &salary);
fprintf(empl, "%-c %ld %g\n", edtype, idnum, salary);
}
}
fclose(empl);
empl = fopen("C:\\Documents and Settings\\MDG\\Assignment 3\\salary.txt", "r");
fscanf(empl, "%c", edtype);
printf("Student Number Education Type Salary\n");
printf("------------------------------------------------------\n");
while(!feof(empl))
{
fscanf(empl, "%ld %c %f", &idnum, &edtype, &salary);
printf("%ld %-c $%7.2f\n", idnum, edtype, salary);
fscanf(empl, "%c", edtype);
}
fclose(empl);
}
As with the last time, it's likely to be something trivial. I just can't see the problem now. I'll keep working on it until I do find a fix, but suggestions would be helpful.