Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[]){
- FILE *sysFile;
- int data[100][4];
- int playercount[100][3];
- int gcount[15][2];
- int hcount[15][2];
- int fileWord;
- int counter = 0;
- int time,player,points;
- char team;
- int x = 0;
- int gpointCounter = 0;
- int hpointCounter = 0;
- int totalG = 0;
- int totalH = 0;
- int totalGOne = 0, totalGTwo = 0, totalGThree = 0, totalGFour = 0;
- int totalHOne = 0, totalHTwo = 0, totalHThree = 0, totalHFour = 0;
- if(argc < 2){
- printf("Error: use %s filename to run program\n", argv[0]);
- exit(1);
- }
- sysFile = fopen(argv[1], "r");
- if(sysFile == NULL){
- printf("Error: file %s not available\n", argv[1]);
- exit(1);
- }
- for(int i = 0; i < 100; ++i){
- playercount[i][2] = 0;
- }
- fscanf(sysFile, "%d %c %d %d", &time, &team, &player, &points);
- while ( !feof(sysFile) )
- {
- data[x][0] = time;
- data[x][1] = team;
- data[x][2] = player;
- data[x][3] = points;
- printf("%d %c %d %d \n", data[x][0], data[x][1], data[x][2], data[x][3]);
- if(data[x][0] < 600){
- if(data[x][1] == 'G'){
- gpointCounter += data[x][3];
- totalGOne += data[x][3];
- playercount[x][0] = 'G';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team G 1/4\n", data[x][2], data[x][3]);
- // printf("total G points 1/4 = %d\n", gpointCounter);
- }else{
- hpointCounter += data[x][3];
- totalHOne += data[x][3];
- playercount[x][0] = 'H';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team H 1/4\n", data[x][2], data[x][3]);
- // printf("total H points 1/4 = %d\n", hpointCounter);
- }
- // printf("Total 1/4 G = %d\n", gpointCounter);
- // printf("Total 1/4 H = %d\n", hpointCounter);
- }
- if((data[x][0] > 600)&&(data[x][0] < 1200)){
- if(data[x][1] == 'G'){
- gpointCounter += data[x][3];
- totalGTwo += data[x][3];
- playercount[x][0] = 'G';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team G 2/4\n", data[x][2], data[x][3]);
- // printf("total G points 2/4 = %d\n", gpointCounter);
- }else{
- hpointCounter += data[x][3];
- totalHTwo += data[x][3];
- playercount[x][0] = 'H';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team H 2/4\n", data[x][2], data[x][3]);
- // printf("total H points 2/4 = %d\n", hpointCounter);
- }
- // printf("Total 2/4 G = %d\n", gpointCounter);
- // printf("Total 2/4 H = %d\n", hpointCounter);
- }
- if((data[x][0] > 1200)&&(data[x][0] < 1800)){
- if(data[x][1] == 'G'){
- gpointCounter += data[x][3];
- totalGThree += data[x][3];
- playercount[x][0] = 'G';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team G 3/4\n", data[x][2], data[x][3]);
- // printf("total G points 3/4 = %d\n", gpointCounter);
- }else{
- hpointCounter += data[x][3];
- totalHThree += data[x][3];
- playercount[x][0] = 'H';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team H 3/4\n", data[x][2], data[x][3]);
- // printf("total H points 3/4 = %d\n", hpointCounter);
- }
- // printf("Total 3/4 G = %d\n", gpointCounter);
- // printf("Total 3/4 H = %d\n", hpointCounter);
- }
- if((data[x][0] > 1800)&&(data[x][0] < 2400)){
- if(data[x][1] == 'G'){
- gpointCounter += data[x][3];
- totalGFour += data[x][3];
- playercount[x][0] = 'G';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team G 4/4\n", data[x][2], data[x][3]);
- // printf("total G points 4/4 = %d\n", gpointCounter);
- }else{
- hpointCounter += data[x][3];
- totalHFour += data[x][3];
- playercount[x][0] = 'H';
- playercount[x][1] = data[x][2];
- playercount[x][2] += data[x][3];
- printf("Player %d got %d points on team H 4/4\n", data[x][2], data[x][3]);
- // printf("total H points 4/4 = %d\n", hpointCounter);
- }
- // printf("Total G = %d\n", gpointCounter);
- // printf("Total H = %d\n", hpointCounter);
- }
- printf("\n");
- x += 1;
- fscanf(sysFile, "%d %c %d %d", &time, &team, &player, &points);
- }
- printf(" 1 2 3 4 total\n");
- printf("G: %02d %02d %02d %02d %02d\n", totalGOne, totalGTwo, totalGThree, totalGFour, gpointCounter);
- printf("h: %02d %02d %02d %02d %02d\n", totalHOne, totalHTwo, totalHThree, totalHFour, hpointCounter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement