#include #include #include #define CATEGORIES 17 char string[4096]; char seps[] = " ,\t\n"; char *token; char *answers[4096]; struct tag_root_test { char *test_name; double sum; int count; double normalized; } root_test[CATEGORIES] = { { "Empty-16", 0.0, 0, 0.0 }, { "Newton-0", 0.0, 0, 0.0 }, { "Omega-1", 0.0, 0, 0.0 }, { "Omega-2", 0.0, 0, 0.0 }, { "Omega-3", 0.0, 0, 0.0 }, { "Omega-4", 0.0, 0, 0.0 }, { "Omega-5", 0.0, 0, 0.0 }, { "Omega-6", 0.0, 0, 0.0 }, { "Omega-7", 0.0, 0, 0.0 }, { "Omega-8", 0.0, 0, 0.0 }, { "Omega-9", 0.0, 0, 0.0 }, { "Omega-10", 0.0, 0, 0.0 }, { "Omega-11", 0.0, 0, 0.0 }, { "Omega-12", 0.0, 0, 0.0 }, { "Omega-13", 0.0, 0, 0.0 }, { "Omega-14", 0.0, 0, 0.0 }, { "Omega-15", 0.0, 0, 0.0 } }; int main(void) { int index; int i; /* Establish string and get the first token: */ while (fgets(string, sizeof string, stdin) != NULL) { token = strtok(string, seps); index = 0; while (token != NULL && index < 3) { /* While there are tokens in "string" */ answers[index] = token; index++; /* Get next token: */ token = strtok(NULL, seps); } for (i = 0; i < CATEGORIES; i++) { if (strcmp(answers[0], root_test[i].test_name) == 0) { root_test[i].sum += atof(answers[1]); root_test[i].count++; } } } for (i = 0; i < CATEGORIES; i++) { root_test[i].normalized = root_test[i].sum / root_test[i].count; if (i != 0) root_test[i].normalized -= root_test[0].normalized; } for (i = 0; i < CATEGORIES; i++) printf("%10.2f, %d,%10s %.2f %d %.2f\n", root_test[i].sum, root_test[i].count, root_test[i].test_name, root_test[i].normalized, i, root_test[i].normalized/(2*i + 1) ); return 0; }