Ok i am writing a program with Arrays and could use a little help. I have to build a two dimensional array with data from a file. The file has date that first is two numbers followed by a list of charterers. So the fist line of data is 2 4ABCDEFGH which is 2 Rows and 4 Columns and array that looks like A B C D
E F G H
I need to have a function to read in the array and then a function to print the array. I am having trouble reading the rows and columns from the file and getting them in the array. Where R is 2 and C is 4 i Tried
infile>>R>>C
Array[R][C]={ }; // It kept saying i had an array of value 0
I am also not sure my function prototype and function header are right and this is really giving me some problems. The only way i can get it to work is by making R and C global and setting them equal to an integer not reading the value from the file. I am also have troubling filling the array with the charterers.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
const int C=4;
const int R=2;
void showarray(char [][C], int,char);
int _tmain(int argc, _TCHAR* argv[])
{ int rows,cols;
char X;
ifstream infile;
ofstream outfile;
infile.open("Infile.txt");
infile>>rows>>cols;
infile>>X;
char Array[R][C]={ };
showarray(Maze,R,X);
return 0;
}
void showarray(char Array[][C], int R,char X)
{
for(int row=0; row<R; row++)
{ for(int col =0; col<C; col++)
{Array[row][col]=X;
{cout<<Array[row][col];}
}
}
cout<<endl;
}