// RESULTS.C - tallys results of Contest #6 #include #include #include #include #include #include #include #include #include #include // defines #define CITIES 38 #define JUDGES 23 #define CATEGORIES 18 #define MAX_NAME_LEN 20 #define MAX_STR_LEN 100 #define TRUE 1 #define FALSE 0 #define BYTE unsigned char // typedefs typedef struct aCity { BYTE vote[ CATEGORIES ]; char strCityName[ MAX_NAME_LEN ]; } typeCity; typedef struct aJudge { typeCity city[ CITIES ]; char strJudgeName[ MAX_NAME_LEN ]; } typeJudge; typedef struct aCat { char strCatName[ MAX_STR_LEN ]; } typeCat; // function prototypes void ProcessFile( void ); int GetCurrentCity( void ); int GetCurrentJudge( void ); int GetVote( void ); char *ReadFile( char *pszName, size_t size ); void DisplayResults( void ); void DisplayTables( void ); void DisplayWhoVoted( int, int ); // globals typeCity city[ CITIES ]; typeJudge judge[ JUDGES ]; typeCat cat[ CATEGORIES ]; int bCurrentJudge = 255; int bCurrentCity = 255; char strCurrentCity[ MAX_NAME_LEN ]; char strCurrentJudge[ MAX_NAME_LEN ]; int bGetCurrentCity = TRUE; char *pc; int main( int argc, char *argv[] ) { char *pcHead; int j, i, c; struct _find_t c_file; unsigned int uiRet; for ( c=0; c JUDGES ) ) { printf( "ERROR: Current Judge out of range 0-%d (%d)\n", JUDGES, bCurrentJudge ); break; } if ( ( bCurrentCity < 0 ) || ( bCurrentCity > 37 ) ) { printf( "ERROR: Current Judge out of range 0-37 (%d)\n", bCurrentCity ); break; } if ( ( iVote < 1 ) || ( iVote > 18 ) ) { printf( "ERROR: Vote out of range 1-18 (%d)\n", iVote ); break; } city[ bCurrentCity ].vote[ iVote-1 ]++; judge[ bCurrentJudge ].city[ bCurrentCity ].vote[ iVote-1 ]++; // printf( " Judge: %d %s City: %d %s Vote: %d = %d %d\n", // bCurrentJudge, // judge[ bCurrentJudge ].strJudgeName, // bCurrentCity, // city[bCurrentCity].strCityName, // iVote, // judge[ bCurrentJudge ].city[ bCurrentCity ].vote[ iVote-1 ], // city[ bCurrentCity ].vote[ iVote-1 ] ); } pc++; if ( *pc == (char) NULL ) break; } } int GetCurrentCity( void ) { char *p; int n, i; p = pc; while( ( *p != ' ' ) && ( *p != 0x09 ) ) p++; n = p - pc; strncpy( strCurrentCity, pc, n ); strCurrentCity[n] = (char) 0; pc = p; for ( i=0; i0; v-- ) // JUDGES is used because no city can have more than JUDGES votes { for ( c=0; c 96 ) printf( " %c", judge[j].city[c].vote[i] ); else printf( "%3d", judge[j].city[c].vote[i] ); printf( "\n" ); } printf( "\n" ); } }