I have been trying to figure out why it will not get past print the chart. I get past the chart and get no data but zeros. unable to debug. Please help.
Code:
# include <stdio.h>
# include <stdlib.h>
#include <limits.h>
#define ROWS 12
#define COLUMNS 8
#define _CRT_SECURE_NO_DEPRECATE
//Function Declarations
int** buildTable (void);
void fillTable (int** table);
void processTable (int** table);
int smaller (int first, int second);
int larger (int first, int second);
int rowMinimum (int* rowPtr);
int rowMaximum (int* rowPtr);
float rowAverage (int* rowPtr);
int main (void)
{
//Local Declarations
int** table;
//Statements
table = buildTable();
fillTable (table);
processTable (table);
system ("PAUSE");
return 0;
}// end of main
/*==============================buildTable=====================================
Creates backbone of the table by creating an array of pointers, each pointing
to an array of intergers.
Pre: Nothing
Post: Returns pointer to the table.
*/
int** buildTable (void)
{
//Local Declarations
//int rowNum;
//int colNum;
int** table;
int row;
//Statements
// printf("\nEnter the nuber of rows in the table:");
// scanf ("%d", &rowNum);
table = (int**) calloc (ROWS + 1, sizeof(int*));
for (row = 0; row < ROWS; row++)
{
//printf("Enter number of intergers in row %d: ", row + 1);
//scanf ("%d", &colNum);
table[row] = (int*)calloc(COLUMNS + 1, sizeof (int));
table[row][0] = COLUMNS;
}//end for
table[row] = NULL;
return table;
}//buildTable
/*=============================fillTable=======================================
This function fills the array rows with data.
Pre: array of pointers
Post: array filled
*/
void fillTable (int** table)
{
//Local Declarations
FILE* spTable;
// int i;
int row = 0;
int column = 0;
//Statements
printf("\n============================================================");
printf("\n\t\tNow we fill the table.\n");
spTable = fopen ("c:\\12-8data.txt", "r");
printf("\n============================================================\n");
if (!spTable)
{
printf ("Could nopt open 12-8data.txt file.\a\n");
exit (101);
}// if open fails
for (int i = 0; i = ROWS * COLUMNS; i++)
{
fscanf(spTable, "%d", &table[row][column]);
printf ("%d\t", table[row][column]);
column++;
if (column==COLUMNS)
{
printf("\n");
row++;
column = 0;
}
}
return;
}//fillTable end
/*==============================processTable===================================
Process the table to create the statistics.
Pre: Table
Post: Column statistics (min., max., and average)
*/
void processTable (int** table)
{
//Local Declarations
int row = 0;
int rowMin;
int rowMax;
float rowAve;
//Statements
while ( table[row] != NULL)
{
rowMin = rowMinimum (table[row]);
rowMax = rowMaximum (table[row]);
rowAve = rowAverage (table[row]);
printf("\n The statistics for Row %d", row + 1);
printf("\n The minimum: %5d", rowMin);
printf("\n The maximum: %5d", rowMax);
printf("\n The average: %5d", rowAve);
row++;
}//while
return;
}//processTable
/*============================rowMinimum=======================================
Determine the minimum of the data in a column.
Pre: given pointer to the column
Post: returns the minimum for that column
*/
int rowMinimum (int* rowPtr)
{
//Local Declarations
int rowMin = INT_MAX;
//Statements
for (int column = 0; column <= *rowPtr; column++)
rowMin = smaller (rowMin, *(rowPtr + column));
return rowMin;
} //colMinimum
/*===========================rowMaximum========================================
Calculate the maximum of the data in a column.
Pre: given pointer to the column
Post: returns the maximum for that column
*/
int rowMaximum (int* rowPtr)
{
//Local Declaration
int rowMax = INT_MIN;
//Statements
for(int column = 0; column <= *rowPtr; column++)
rowMax = larger (rowMax, *(rowPtr + column));
return rowMax;
}// colMaximum
/*============================colAverage=======================================
This function calculates the average of data in a column.
Pre: pointer to the column
Post: returns the average for that column
*/
float rowAverage (int* rowPtr)
{
//Local Declaration
float total = 0;
float rowAve;
//Statements
for (int column = 0; column <= *rowPtr; column++)
total += (float)*(rowPtr + column);
rowAve = total / *rowPtr;
return rowAve;
}//colAverage
/*================================smaller======================================
This function returns the smaller of two numbers.
Pre: two numbers
Post: returns the smaller
*/
int smaller (int first, int second)
{
//Statements
return (first < second ? first :second);
} //smaller
/*=================================larger======================================
This function returns the larger of two numbers.
Pre: two numbers
Post: returns the larger
*/
int larger (int first, int second)
{
//Statements
return ( first > second ? first : second);
}//larger
I am trying to got to column calulations but just want it to work with rows first.
Code:
838 758 113 515 51 627 10 419
212 86 749 767 84 60 225 543
89 183 137 566 966 978 495 311
367 54 31 145 882 736 524 505
394 102 851 67 754 653 561 96
628 188 85 143 967 406 165 403
562 834 353 920 444 803 962 318
422 327 457 945 479 983 751 894
670 259 248 757 629 306 606 990
739 516 414 262 116 825 181 134
343 22 233 536 760 979 71 201
336 61 160 5 729 644 475 993
the data text 12-8 data text file. Could some one please help.