Hi everyone. Am unable to figure out why this for loop doesnt work. The loop variable jumps straight to 10 without running through 1,2,3,4 etc, and the inner loop just automatically jumps to flag=1. Dispite this, both loops continue indefinitely (when they should stop at these values). Can anyone figure out why? The program runs so dont have any errors
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
FILE *fp;
int loop=1;
int signalOutput;
int flag=0;
int column1;
float column2;
float temperatureArray[10];
int quit;
srand(time(NULL));
printf("\n\n The sensor readings and their corresponding temperatures:\n");
fp = fopen("c:\\LOOKUP.txt", "r");
for( ; loop=10; ++loop)
{
signalOutput = (int)(rand()%15);
for(flag=0; flag=1; 0)
{
fscanf(fp, "%i %f",&column1, &column2);
if ( signalOutput <= column1 )
{
temperatureArray[loop] = column2;
flag = 1;
printf("\n the %i reading was %i = %f", loop, signalOutput, temperatureArray[loop]);
}
}
}
fclose(fp);
printf("Press enter to quit");
scanf("%i", &quit);
return 0;
}
the text file contains:
0 10
1 12
2 14
3 16
4 18
5 20
6 21
7 22
8 23
9 24
10 24.5
11 25
12 25.25
13 25.5
14 25.75
15 26
hopefully we can figure out whats wrong with this
thanks and all the best