This is what I have so far for code. I am trying to read the file.. that contains data that looks like this.

Std# T1 T2 T3 T4 T5
1234 54 65 44 44 78
4561 78 78 87 87 87

and so on. My problem is the idea is to set it up to be avaliable to recieve data for up to 40 students but right now I only have 15. When I go to print the Raw data, it prints a bunch of garbage and wierd numbers for all the other places in the array. I thought I had it so it would only read the data. Also my Average part gives me a floating exception point error.. I would appreciate anyones help or ideas. I have tried to comment as much as I could to make things easy to read.

If you have any questions my email is [email protected] and your help would be greatly appreciated.

Thank you..

Ryan P



/* Input: This program is divided into three parts.
Part 1: p5.h : is the header of the program.
Part 2: p5m.c : is the function MAIN of the program.
Part 3: p5f.c : is the series of companion functions.

The program will use data from the file p5.in
Makefile is then used to compile the three together.
*/
/* Output: The output for the program will be sent directly to the monitor.
*/


#include <stdio.h>
#include <stdlib.h>

#define MAX_ROWS 40
#define MAX_COLS 5

// Prototype Declarations

int getStuData (int StdNum[], int table[MAX_ROWS][MAX_COLS],
float StdAverage[MAX_ROWS]);
void printRawData(int size, int StdNum[], int table[][MAX_COLS]);
void testAverage (int table[][MAX_COLS], float testAve[], int size);
void printResults (int table[][MAX_COLS], int StdNum[], float StdAverage[],
float testAve[], int size);

int main(void)
{
//Local Definitions

int size;
int table [MAX_ROWS][MAX_COLS];
int StdNum [MAX_ROWS];
float StdAverage [MAX_ROWS] = {0};
float testAve [MAX_COLS] = {0};

//Function Calls

size=getStuData (StdNum, table, StdAverage);
printRawData(size, StdNum, table);
testAverage (table, testAve, size);
printResults (table, StdNum, StdAverage, testAve, size);

return 0;
}
//end of Main


/*------------ getStuData-------------------
This function reads the file p5.in
and then stores the student numbers into a
array.
*/

int getStuData (int StdNum[MAX_ROWS], int table[MAX_ROWS][MAX_COLS],
float StdAverage[MAX_ROWS])
{
// Local Definitions

FILE *fp;
int row=0;
int col=0;
int rowAve;
int Okscan;

if (!(fp = fopen ("p5.in", "r")))
printf("Error opening File\a\a\n") , exit (100);

while(row<MAX_ROWS)
{
rowAve=0;
for(col=0; col<6; col++)
{
if (col==0)
{
Okscan=fscanf(fp, "%d", &StdNum[row]);
if(!Okscan)
break;
}
if (col!=0)
{
fscanf(fp, "%d", &table[row][col-1]);
rowAve+=table[row][col-1];
}
}
if(Okscan)
{
StdAverage[row]=(rowAve/5);
row++;
}
else
break;
}
fclose(fp);
return row;
}


void printRawData(int size, int StdNum[], int table[][MAX_COLS])
{
//Local Definitions
int row=0;
int col=0;

system("clear");

printf("\n\t\t RAW DATA REPORT\n");
printf("Student # Test1 Test2 Test3"
" Test4 Test5\n");
printf("---------------------------------------"
" ----------------");
for(row=0; row < size; row++)
{
printf("\n%7d", StdNum[row]);
for(col = 0; col<MAX_COLS; col++)
printf("%6d", table[row][col]);
}
printf("\n\n\nDepress <enter> key to continue: ");
getc(stdin);
fflush(stdin);
}



/*--------------testAverage--------------
This function will average the students scores
for each test individually.
*/

void testAverage (int table[][MAX_COLS], float testAve[], int size)
{
//Local Definitions
int row=0;
int col=0;

for(row=0; row < size; row++)
{
for(col = 0; col<MAX_COLS; col++)
testAve[row] += table[row][col];
testAve[row]/MAX_COLS;
}
}


/*-------------printResults---------------
This function will display the Average
data report.
*/

void printResults (int table[][MAX_COLS], int StdNum[], float StdAverage[],
float testAve[], int size)
{
int row=0;
int col=0;
system("clear");
printf("\t\t STATISTICAL REPORT");
printf("\nStudent Test1 Test2 Test3"
" Test4 Test5 Average");
printf("\n---------------------------------------"
" ----------------");

for(row=0; row < size; row++)

{
printf("\n%7d", StdNum[row]);

for(col = 0; col<MAX_COLS; col++)
printf("%6d", table[row][col]);
printf(" | %6.2f", StdAverage[row]);
}

printf("****************************************** **********\n");
printf("Average: ");
for(col = 0; col<MAX_COLS; col++)
printf("%6.2f", testAve[col]);
printf("\n\n\nDepress <enter> key to continue: ");
getc(stdin);
fflush(stdin);

return;
}