So I'm new in C programming and I am having trouble using my text file to input to my program.This is a program that inputs a text file to the program. But after it compiles, it doesn't input the data. Can someone please help me find out what is wrong? Thank you!
Here is the text file: masks.txt
4
32 67 56 88 172 210 316 400 288 321
47 69 78 100 121 155 467 560 199 278
25 61 72 102 160 225 319 399 171 212
25 41 82 102 160 225 309 388 271 293
CODE:
#include <stdio.h>
#include <limits.h>
#define BUFFERSIZE 100
int main(int argc, char *argv[])
{
FILE *fp;
char ch;
fp = fopen("masks.txt", "r");
if (fp == NULL)
{
printf("Error. File not found!\n");
return (-1);
}
char buffer[BUFFERSIZE];
fgets(buffer, BUFFERSIZE, stdin);
int n, count = 0, days = 1;
float sum = 0, total = 0, min = INT_MAX, max = INT_MIN;
float lowest = INT_MAX, highest = INT_MIN;
scanf("%d", &n);
printf("Project #4\n");
printf("Number of days: ", n);
printf("\n\n");
printf("\t\t t1\t t2\t t3\t t4\t t5\t Aver\t Min\t Max\n");
printf("\t\t-----\t-----\t-----\t-----\t-----\t-----\t-----\t-----\n");
while (!feof(fp))
{
if (count % 5 == 0)
{
printf("day #", days, ":\t\t");
days++;
}
int withMasks, totalPeople;
scanf("%d", withMasks);
scanf("%d", totalPeople);
float percentage = (withMasks / totalPeople) * 100;
if (percentage > max)
{
max = percentage;
}
else if (percentage < min)
{
min = percentage;
}
else if (percentage > highest)
{
highest = percentage;
}
else (percentage < lowest);
{
lowest = percentage;
}
sum += percentage;
printf("%0.1f%%\t", percentage);
count++;
if (count % 5 == 0)
{
printf("%0.1f%%\t", (sum / 5));
printf("%0.1f%%\t", min);
printf("%0.1f%%\t", max);
total += (sum / 5);
sum = 0;
min = INT_MAX, max = INT_MIN;
printf("\n");
}
}
printf("\n\nOverall average: %0.1f%%", (total / n));
printf("\nLowest overall: %0.1f%%", lowest);
printf("\nHighest overall: %0.1f%%", highest);
fclose(fp);
return 0;