I have a homework problem that I could really use some help on. Here are the directions: write a program to read a set of scores from a text file, count the scores over 90, copy the scores over 90 to a new file and print the number of scores over 90 to the monitor.
I hope I did this correctly. I thought that this would be pretty easy but I can't see my problem. please help.Code:#include <stdio.h>
#include <stdlib.h>
int newlist(int score);//function declaration
FILE* spData;// file to read from
FILE* spnewList;
int score;//global variable dec.
char name;
int main()//main
{
int below = 0; //local declarations
int count = 0;
printf("This program will print scores over 90%\n");
spData = fopen("TextFile1.txt", "r");
if (!spData)
{
printf("Could not open file \a\n");
exit (101);
}//if open fails
while (!EOF)
fscanf(spData, " %d", &score);
if (score > 90)
{ 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);
newlist(score);
return 0;
}//main
/*=================newlist==================*/
int newlist(int score)//writes info to new file
{
spnewList = fopen("Gradelist.txt", "w");//creates new file
if (score > 90)
fprintf(spnewList, " %d", score);
return 1;
}//newlist
I guess I should add that it does compile but doesn't open the file.