need help im reading in a file that has a list
0 2
1 4
0 2
1 2
so if there is a one in the first column it will tell me the location of my first max. So my first max is location 2 and i need it to print to the screen. I am completly lost on how to do this any help?
Code:
/* Number 10 */
#include<stdio.h>
#include<math.h>
#define FILENAME "exam1.dat"
main()
{
/* Define Variables*/
int n_d_p=0,col_1,col_2, locmax, i;
double sum=0.0,max,min,ave,flag_0=0,flag_1=0;
FILE *list1;
/* Opening External File */
list1=fopen(FILENAME,"r");
/* Reading the numbers in opened file */
while((fscanf(list1,"%i %i",&col_1,&col_2))==2)
{
/* Computing The Average */
if(col_1==1)
{
sum +=col_2;
n_d_p++;
/* Max Calcualtion */
if(col_1==1)
{
if(flag_1==0)
{
flag_1=1;
max=col_2;
}
if(col_2>max)max=col_2;
}
}
}
/* First Max *********NEED HELP HERE******/
if(col_1==1)
ave=sum/n_d_p;
printf("Average: %7.2f \n",ave);
printf("Maximum: %4i \n",max);
printf("Loc of first max: %4i \n",locmax);
fclose(list1);
/*exit program*/
return 0;