This is homework and I am using a getfile that is just a 5 row 4 column list of numbers. I can get this program to compile and when I go to run it, I get my cout text output but without my numbers and the program crashes. I am sure it is something to do with the way I call my functions. But I am so lost now. Any help is appreciated.
#include<iostream>
#include<fstream>
using namespace std;
const int ROWS = 5, COLS = 4;
//function prototypes
void Bubble_Sort(int,int,int[][COLS]);
void Show_Array(int,int,int[][COLS]);
int a[ROWS][COLS];
int main(int argc, int *argv[])
{
int r,c,row,col;
int a[ROWS][COLS];
//read the data file
ifstream inFile("data.dat");
//fill the array
cout<<"\nData Before Sorting:" <<endl;
inFile >>row >>col;
for(r=0; r<row; r++)
{
for (c=0; c <col; r++)
{
cout<< a[r][c] << " ";
}
}
//call the functions
//sort the array
Bubble_Sort(ROWS,COLS,a);
//display the sorted array
cout<<"\nData After Exchange:" <<endl;
Show_Array(ROWS,COLS,a);
return 0;
}//end of main
void Bubble_Sort(int ROWS,int COLS,int a[][4])
{
int* p = (int*)a;
int r,c,n(ROWS*COLS);
for(r=0; r<(n-1); r++)
{
for(c=r+1; c<n; c++)
{
if(p[r] > p[c])
{
int hold = p[r];
p[r] = p[c];
p[c] = hold;
}
}
}
}//end sort
void Show_Array(int ROWS,int COLS,int a[][4])
{
int r,c;
for(r=0; r<ROWS; r++)
{
for(c=0; c<COLS; c++)
{
Show_Array(ROWS,COLS,a);
}
Show_Array(ROWS,COLS,a);
}
}//end show sorted
//end of file