Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
struct variables {
int time;
int brakefluid;
int diskpressure;
int driverpressure;
int power;
};
int main()
{
FILE *fout, *finrecorded;
fout=fopen("variables.txt", "w");
finrecorded=fopen("variables.txt", "r");
int count = 0;
int i = 0;
struct variables crash[1000];
for (i=0; i<1000; i++)
{
crash[i].time = i;
crash[i].brakefluid = rand()%100;
crash[i].diskpressure = rand()%100;
crash[i].driverpressure = rand()%100;
crash[i].power = rand()%100;
count++;
}
//while(!feof(finrecorded)) {
//fscanf(finrecorded, "%d ", &population[i]); // Populates the array with floating points from the file
//i++;
//count++;
//}
printf("Time Brake Fluid Disk Pressure Driver Pressure Power to unit");
for(i = 1; i < 1000; i++) { // start at 1 because -1 was still getting input into the array because I was using the count instead of a size variable
fprintf(fout, " %d %d %d %d %d ", crash[i].time, crash[i].brakefluid, crash[i].diskpressure, crash[i].driverpressure, crash[i].power);
finrecorded=fopen("variables.txt", "r");
printf(" %d %d %d %d %d ", crash[i].time, crash[i].brakefluid, crash[i].diskpressure, crash[i].driverpressure, crash[i].power);
printf("\n");
}
fclose(fout);
fclose(finrecorded);
return 0;
}
Okay so I now have the correct setup for my structure with the five variables. Everything is now working the way it should except that I still don't understand how to get the loop to behave in a circular fashion replacing the variables with only the latest 100 iterations of the 1000 iteration loop.
Any help would be greatly appreciated.