All pastes #995383 Raw Edit

Combat log parser

public c v1 · immutable
#995383 ·published 2008-04-24 02:57 UTC
rendered paste body
// ---------------------------------------------------------------------------// Program name:     Lord of the Rings Online Combat Log Parser// Program number:   Final// Submitted by:     Ryan Salisbury//// Credit to:        http://www.codecodex.com/wiki/index.php?title=Bubble_sort#C//                   For Bubble sort function//                   http://www.tek-tips.com/viewthread.cfm?qid=1394492&page=1//                   For string search//                   http://www.cplusplus.com/reference/clibrary///                   For large amounts of function reference//// Submitted on:     April 22, 2008// By submitting this program with my name, I affirm that the creation// and modification of it is primarily my own work.// ---------------------------------------------------------------------------#include "stdlib.h"#include "stdio.h"#include "string.h"#include "math.h"typedef struct {        char fName[25];        char sName[25];        int damage;        char skill[40];        int isHeal; //1 = true, 0 = false}info;typedef struct {        int min;        int max;        float mean;        float std;}stats; //not used int setupRead(FILE *in);int getStrings(FILE *in, int lineCount, info s);void readString(char line[128], info i);void menus();void calcStats(info i[], int arg, int y);void bubbleSort(int *array, int length);void printInfo(info i[], int c); int main() {     menus();}int setupRead(FILE *in) {    char temp[128];    int lineCount = 0;    while(!feof(in)) {         fgets(temp, 128, in);         lineCount++;    }    return --lineCount;}int getStrings(FILE *in, int lineCount, info s) { //this will have to change somehow so                                                   // I can use the output; dur.     char temp[128];                               // yay for not thinking ahead.     int arrayInd1 = 0, arrayInd2 = 0, strLength, x = 0, y = 0, z = 0;         fgets(temp, 128, in);     temp[strlen(temp)-1] = 0;     system("pause");     readString(temp, s);     return 1;}void readString(char line[], info i) { //Apparently this is borked.     char *mark1;     char *mark2;     char damage[5], tempd[4];     int x, length;     mark2 = strstr(line, "wounds");     //no problem until here          if(mark2 != NULL) { //break point           i.isHeal = 0;           length = strlen(line) - strlen(mark2); //break point           strncpy(i.fName, line, length);           mark1 = mark2+6;     }     else if(strstr(line, "wound") != NULL) {           i.isHeal = 0;           length = strlen(line) - strlen(mark2);           strncpy(i.fName, line, length);           mark1 = mark2+5;     }     else if(strstr(line, "heals") != NULL) {           i.isHeal = 1;           length = strlen(line) - strlen(mark2);           strncpy(i.fName, line, length);           mark1 = mark2+5;     }          else if(strstr(line, "heal") != NULL) {           i.isHeal = 1;           length = strlen(line) - strlen(mark2);           strncpy(i.fName, line, length);           mark1 = mark2+4;     }     if(strstr(line, "with") != NULL) {           mark2 = strstr(line, "with");           length = mark2 - mark1;           strncpy(i.sName, mark1, length);           mark1 = mark2+4;     }     else {           mark2 = strstr(line, "for");           length = mark2 - mark1;           strncpy(i.sName, mark1, length);           mark1 = mark2+3;     }     mark2 = strstr(line, "points");     length = mark2 - mark1;     strncpy(damage, mark1, length);     mark2 = strstr(damage, ",");     length = strlen(damage) - strlen(mark2);     strncpy(tempd, damage, length);     strncat(tempd, ++mark2, length);}void menus() {     int sCase, lCount, x, arg, b = 0, y, z, w;     char fileName[50]; //default file     FILE *in;     strcpy(fileName, "Death_20080113_1.txt");     in = fopen(fileName, "r");     int index = setupRead(in);     info s[index];     /*   Workaround   */     int dmgs[] = {58, 54, 82, 82, 54, 95, 54, 54, 82, 54, 54, 54, 95, 54, 56, 98, 84, 56, 84, 56, 61, 152};          info workAround[22];     for(w = 0; w < 22; w++) {           strcpy(workAround[w].fName, " ");           strcpy(workAround[w].sName, "you");           workAround[w].damage = dmgs[w];           workAround[w].isHeal = 0;     }     /* End workaround */     do {         system("cls");         printf("   LotRO Combat Log Parser v0.1\n");         printf("===================================\n");         printf("Choose option:\n 1. Open Log (Current file: %s)\n 2. Parse Current Log\n 3. View\n 4. Exit\n 5. About\n 6. Output workaround (no file req'd)\nNote: Type 9 at any time to go to top menu\n", fileName);         scanf("%i", &sCase);         switch(sCase) {               case 0:                    system("cls");               case 1:                    printf("Type file name (exclude extension)\n");                    scanf("%s", &fileName);                    strcat(fileName, ".txt");                    in = fopen(fileName, "r");                    if(in == NULL) {                           system("cls");                          printf("File does not exist.\n");                          fclose(in);                          system("pause");                    }                    break;               case 2:                    lCount = setupRead(in);                    z = 0;                    for(x = 0; x < lCount; x++) {                         y = getStrings(in, lCount, s[x]);                         system("cls");                         if(y) {                            z++;                            printf("%i of %i...", z, lCount);                         }                         else {                            printf("Error!");                            break;                         }                                             }                    system("cls");                    printf("Operation Successful.\n");                    fclose(in);                    system("pause");                    break;               case 3:                    system("cls");                    printf("Choose option:\n 1. My incoming damage\n 2. My outgoing damage\n 3. My incoming healing\n 4. My outgoing healing\n");                    scanf("%i", &arg);                    calcStats(s, arg, lCount);                    break;               case 4:                    exit(0);                    break;               case 5:                    system("cls");                    printf("LotRO Combat Log Parser v0.1\nAuthor: Ryan Salisbury (TSRX/Amurard)\nContact: warthogpilot@gmail.com\n\n\n");                    system("pause");                    break;               case 6:                    system("cls");                    printf("Choose option:\n 1. My incoming damage");                    scanf("%i", &arg);                    calcStats(workAround, arg, 22);                    break;               case 7:               case 8:               case 9:                    b = 1;                    break;               default:                    system("cls");                    printf("NOT AN OPTION.  PREPARE TO DIE.\n\n You have been incapacitated.  Do you want to retreat from battle?\n");                    system("pause");                    b = 1;                    break;               }     } while(b = 1);}void calcStats(info i[], int arg, int y) {     //args: 1. My inc dmg, 2. My out dmg, 3. My inc heal, 4. My out heal     int x, dmgTotal = 0, counter = 1, min = 1000, max = 0, damages[y];     float mean = 0, StD = 0, stdTotal = 0.;     char target[25], inc[8], hord[7], temp[25];          switch(arg) {          case 1:               for(x = 0; x < y; x++) {                     strcpy(temp, i[x].fName); //somehow this works                     if(strcmp(temp, "you")&& i[x].isHeal == 0) {                           damages[x] = i[x].damage;                           dmgTotal += i[x].damage;                           counter++;                     }               }               strcpy(inc, "Incoming");               strcpy(hord, "damage");               break;          case 2:               for(x = 0; x < y; x++) {                     strcpy(temp, i[x].fName);                     if(strcmp(i[x].fName, "You")&& i[x].isHeal == 0) {                           damages[x] = i[x].damage;                           dmgTotal += i[x].damage;                           counter++;                     }               }               strcpy(inc, "Outgoing");               strcpy(hord, "damage");               break;          case 3:               for(x = 0; x < y; x++) {                     strcpy(temp, i[x].sName);                     if(strcmp(i[x].sName, "you")&& i[x].isHeal == 1) {                           damages[x] = i[x].damage;                           dmgTotal += i[x].damage;                           counter++;                     }               }               strcpy(inc, "Incoming");               strcpy(hord, "healing");               break;          case 4:               for(x = 0; x < y; x++) {                     strcpy(temp, i[x].fName);                     if(strcmp(i[x].fName, "You")&& i[x].isHeal == 1) {                           damages[x] = i[x].damage;                           dmgTotal += i[x].damage;                           counter++;                     }               }               strcpy(inc, "Outgoing");               strcpy(hord, "healing");               break;          default:               printf("Improper argument.");               break;     }     counter--;     bubbleSort(damages, counter);     min = damages[0];     max = damages[counter - 1];     mean = (float)dmgTotal / counter;     float deviations[counter];     for(x = 0; x < counter; x++) { //std           deviations[x] = damages[x] - mean;           deviations[x] *= deviations[x];           stdTotal += deviations[x];     }     stdTotal /= counter;     StD = sqrt(stdTotal);     system("cls");     printf("%s %s stats: \n\tTotal: %i\n\tMean: %5.2f\n\tStandard Deviation: %5.2f\n\tMin: %i\n\tMax: %i\n", inc, hord, dmgTotal, mean, StD, min, max);     system("pause");}void bubbleSort(int *array, int length) {//from http://www.codecodex.com/wiki/index.php?title=Bubble_sort#C  int i, j, temp;  int test; /*use this only if unsure whether the list is already sorted or not*/  for(i = length - 1; i > 0; i--) {    test=0;    for(j = 0; j < i; j++) {      if(array[j] > array[j+1]) {/* compare neighboring elements */        temp = array[j];    /* swap array[j] and array[j+1] */        array[j] = array[j+1];        array[j+1] = temp;        test=1;      }    } /*end for j*/    if(test==0) break; /*will exit if the list is sorted!*/  } /*end for i*/      }/*end bubbleSort*///Submission comment repost:/*This doesn't work as intended, the string searching function causes the program to crash.  I have created a workaround option, so everything but the search function works correctly.  I have not commented out the non-working section because it is not necessary to call it for the program to run.  I've tried about five different methods for the string search function and none of them worked correctly.  This source contains the latest attempt.*/