Compiles fine, freezes when Run?
I'm working on an assignment and ran into some problems about halfway through my code, so I decided to start over going a little slower now. However now I've written the first two functions and they look to me like they should work and they compile with no errors. When I hit run though, it doesn't do anything at all and I have to manually end the run process. What it should do is open a data file (containing 56 numbers - 7 numbers in 8 rows) and read each value into an array then print out the array (to check to see if the data file was read correctly). Is there something I've forgotten or maybe written wrong that is causing this to lock up (by lock up I don't mean the screen actually freezes, just the program sits and does nothing)?
Code:
#include<stdio.h>
#define FILENAME "assign8in.txt"
#define nCols 7
#define nRows 8
int read2D(int array[][nCols], int numRows, int numCols);
void print2D(int array[][nCols]);
int main()
{
int array[nRows][nCols];
int numRows, numCols;
int colNum, rowNum;
numRows == nRows;
numCols == nCols;
read2D(array, numRows, numCols);
print2D(array);
return 0;
}
//This function will read the data file into a 2D array.
int read2D(int array[nRows][nCols], int numRows, int numCols)
{
int i, j;
FILE *assign8in;
assign8in = fopen(FILENAME, "r");
if (assign8in == NULL)
printf("Error Opening input file \n");
else
{
for (i=1; i<=numRows; i++)
{
for (j=1; j<=numCols; j++)
{
fscanf(assign8in, "%d", &array[i][j]);
}
}
}
return array[numRows][numCols];
}
// This is a temporary function that will print out the
// array filled by function read2D to check if the
// data was read correctly. To use this function remove
// the /* and */ around the function and remove the // before
// the print2D call in function main and its declaration
// at the beginning of the code.
void print2D(int array[nRows][nCols])
{
int i, j;
for (i=1; i<=nRows; i++)
{
for (j=1; j<=nCols; j++)
{
printf("%3d ", array[i][j]);
}
printf("\n");
}
}