I'm having alot of trouble with the function 'get_stats()'. It's supposed to read/store data and store it in the correct place in the array of structure.
Any help would be greatly appreciated.
Code:
#include "stdafx.h"
#include <string.h>
#include <conio.h>
#include <stdio.h>
#define NMSIZE 21
#define TMSIZE 16
// Self defined structure
typedef struct {
char name[NMSIZE], temp; // The batters name
int runs[101]; // the amount of runs the batter got
int total_runs; // total runs scored byt the batter
double avg_runs; // The average amount of runs scored by the batter
int innings; // The total amount of innings
int b, // bowled
l, // lbw
c, // caught
s, // stumped
r, // ran out
o, // not sure....
not_out; // not geting out in the innings
} batter_t;
void
get_stats(batter_t team_arr[])
{
int i,
input,
truns;
char pname[NMSIZE],
tway_out;
batter_t ;
FILE *ifp;
ifp = fopen("D:\\input2b.dat", "r");
while ( pname !=0 );
input = fscanf (ifp,"%20s %3d %c", pname, &truns, &tway_out);
if (ifp == NULL)
printf("Error reading 'input2a.dat'");
else
for(i = 0; i < TMSIZE; i++) {
if( strcmp(pname, team_arr[i].name) == 0) {
team_arr[i].total_runs = team_arr[i].total_runs + truns;
team_arr[i].innings ++;
tway_out;
if(tway_out == 'c') {
team_arr[i].c ++;
}
else if(tway_out == 'l') {
team_arr[i].l ++;
}
else if(tway_out == 'b') {
team_arr[i].b ++;
}
else if(tway_out == 's') {
team_arr[i].s ++;
}
else if(tway_out == 'r') {
team_arr[i].r ++;
}
else if(tway_out == 'o') {
team_arr[i].o ++;
}
else if(tway_out == 'n') {
team_arr[i].not_out ++;
}
else {
printf("Input error recieved (or no file)");
}
for(i = 1; i <= TMSIZE; i++) {
printf("%21s %3d %2d %4d %6.2f %1d %1d %1d %1d %1d %1d\n", team_arr[i].name,
team_arr[i].innings, team_arr[i].not_out, team_arr[i].total_runs, team_arr[i].avg_runs,
team_arr[i].b, team_arr[i].l, team_arr[i].c, team_arr[i].s, team_arr[i].r, team_arr[i].o); }
}
}
}