here is updated code, it compiles but gives error message "could not open textfile1". I'll have to look into it tomorrow. I must have done something wrong. We just started reading and writing files this week, so I'm sure I am missing something.
Code:
#include <stdio.h>
#include <stdlib.h>
FILE* spData;// file to read from
FILE* spGradelist;
int main()//main
{
int below = 0; //local declarations
int count = 0;
int score;
printf("This program will print scores over 90%%\n");
spGradelist = fopen("Gradelist.txt", "w");
spData = fopen("TextFile1.txt", "r");
if (!spData)
{
printf("Could not open file Textfile1 \a\n");
exit (101);
}//if open fails
while (fscanf(spData, "%*s%d", &score) == 1) {
if (!feof(spData)) {
printf("Error! fscanf stopped, but not due to EOF\n");
}
if (score > 90)
{ fprintf(spGradelist, "%d", score);
count++;}
else
{below++;}
}
printf("The number of scores above 90%% are %d\n", count);
printf("The number of scores below 90%% are %d\n", below);
fclose(spData);
fclose(spGradelist);
return 0;
}//main
I also fixed the space in my fprintf line, thanks for all of your insight. I appreciate it a lot.