I am trying to read data from a text file and print when a person enters a room and when someone exited the room. The text file is data from a sensor our Professor helped us collect. The file contains angles and ranges detected by the sensor (he spelled “angle” as “angel” in the text file).
The problem I am having is the program will read the file and print what I want it to but it will not stop reading the file. I also need to add a counter that will add one each time a person walked in and subtract one every time a person walked out but I cannot add the counter and get it to print until I fix the code and get it to stop reading the text file. My current code is below. Please help me solve this and Thank You!!
#include <stdio.h>
int main() {
FILE *fp;
FILE *op;
int time;
int range;
float i;
float angel;
char str;
fp = fopen("/home/chris/Desktop/test.txt", "rt");
op = fopen("/home/chris/Desktop/Pro.csv", "w");
i=0;
while((str = getc(fp)) != EOF) {
fscanf(fp,"range: %d, ",&range);
fscanf(fp,"angel: %f,",&angel);
if (angel == -10.75)
{
if(range<4100) {
printf("Someone has entered the room\n");
}
}
if (angel == -10.75)
{
if (range>4100 && range<6000)
printf("Someone has left the room\n");
i++;
}
}
fclose(fp);
fclose(op);
return 0;
}