Code:
================================================================
/***************************************************************************
Description: Project 4
Due Date/Time: Friday, April 7, 2006 at 8:00 a.m.
This program is designed to take and integer seed from the OS and
dimensions for a two dimensional array and randomly fill the array of
specified size, calculate the mean and median of each row of data, and
print all data to an output file.
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define MAXROWS 10
#define MAXCOLS 15
int openFiles(int argc, char *argv[], FILE **fpIn, FILE **fpOut);
int readData(FILE *fpIn, int *pRows, int *pCols);
void fillArray(int seed, int rows, int cols, int arr[][]);
void calcMeans(int rows, int cols, int arr[][], double means[]);
void sortArr(int rows, int cols, int arr[][]);
void sort(int cols, int arr[]);
void swap(int *pNum1, int *pNum2);
void display(FILE *fpOut, int rows, int cols, int arr[][], double means[]);
void displayHeader(FILE *fpOut, int cols);
int main(int argc, char *argv[])
{
FILE *fpIn, *fpOut;
int seed, rows, cols;
int arr[rows][cols];
int i, j;
if (openFiles(argc, argv, &fpIn, &fpOut))
{
seed = readData(fpIn, &rows, &cols);
fillArray(seed, rows, cols, arr);
// TEST: REMOVE!
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
printf("%4d", arr[i][j]);
printf("\n");
}
printf("\n\n");
}
return 0;
}
int openFiles(int argc, char *argv[], FILE **fpIn, FILE **fpOut)
{
int success = FALSE;
if (argc == 3)
{
*fpIn = fopen(argv[1], "r");
if (*fpIn != NULL)
{
*fpOut = fopen(argv[2], "w");
if (*fpOut != NULL)
success = TRUE;
else
{
printf("\n\nError: Unable to open Output File.\n\n");
fclose(*fpOut);
}
}
else
{
printf("\n\nError: Unable to open Input File.\n\n");
fclose(*fpIn);
}
}
return success;
}
int readData(FILE *fpIn, int *pRows, int *pCols)
{
int seed;
fscanf(fpIn, "%d %d %d", &seed, &*pRows, &*pCols);
return seed;
}
void fillArray(int seed, int rows, int cols, int arr[rows][cols])
{
int i, j;
srand(seed);
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
arr[i][j] = rand() % 71 + 30;
}
void calcMeans(int rows, int cols, int arr[][], double means[])
{
}
void sortArr(int rows, int cols, int arr[][])
{
}
void sort(int cols, int arr[])
{
}
void swap(int *pNum1, int *pNum2)
{
}
void display(FILE *fpOut, int rows, int cols, int arr[][], double means[])
{
}
void displayHeader(FILE *fpOut, int cols)
{
}
===================================================================
I was searchin the internet to find a way to solve it and I found a debugging compile option...but I dont know anything about it...I just used it and it follows: