Looping an input file and storing the contents based on type(int/char)

This is a discussion on Looping an input file and storing the contents based on type(int/char) within the C Programming forums, part of the General Programming Boards category; I'm having alot of trouble with the function 'get_stats()'. It's supposed to read/store data and store it in the correct ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Looping an input file and storing the contents based on type(int/char)

    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); }
                }
            }
        }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    Your horrible code cannot compile.
    Please post correct code without compiler errors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing contents of an input file to the screen
    By babe20042004 in forum C++ Programming
    Replies: 2
    Last Post: 11-24-2009, 12:57 PM
  2. Help appreciated, storing contents of a file
    By Wsorne in forum C Programming
    Replies: 1
    Last Post: 05-11-2007, 07:11 PM
  3. storing text file contents into a string
    By m.mixon in forum C Programming
    Replies: 4
    Last Post: 07-20-2006, 12:52 PM
  4. Storing data from a file into a single char string
    By tuxinator in forum C Programming
    Replies: 16
    Last Post: 05-01-2006, 11:21 PM
  5. Trouble storing file input in array
    By difficult.name in forum C Programming
    Replies: 1
    Last Post: 10-11-2004, 12:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21