I am using windows vista for my C++ program and a beginner so please keep it simple.
Lets say i have two functions, and one functions which is void contains a array of char [5][5] for example '-' and the second functions is to prompt the user to input anything he want input. How do i call the userinput function and put it into the array of char function? Keep it simple please, thanks in advance.
#include <iostream>
usingnamespace std;
int main()
{
char ArrayOne[26]; // declare a 1-D array
char Array2D[5][5]; // declare the 2-D array
cout << "Input the characters" << endl;
cin >> ArrayOne; // take input
int i, j, index = 0;
// Assign each value from the single array
// to the 2D array
for (i=0; i<5; ++i)
{
for (j=0; j<5; ++j)
{
Array2D[i][j] = ArrayOne[index];
++index;
}
}
// This part only outputs contents of the 2D array
// to see if the above worked
int row, col;
for (row=0; row<5; ++row)
{
for (col=0; col<5; ++col)
{
cout << "Char[" << row << "][" << col << "]" << Array2D[row][col] << endl;
}
}
return (0);
}
The program,
1. takes input from the user and stores it in a 1-dimensional array
2. takes each value from this array and puts in a 2-D array