Thanks for replying,and pointing the flaws.
But still ....its showing compile errors.
error C2109: subscript requires array or pointer type.(on the last line).
I have not started with chapter pointera yet.
the modified code:
Code:
#include <iostream>
using namespace std;
const int MAX_NAMES =3;
const int MAX_LENGTH=6;
char getname();
void displayarray(const char [][6],int, int);
int main()
{
char arrays[3][6];
getname();
displayarray(arrays, MAX_NAMES,MAX_LENGTH);
return 0;
}
char getname()
{
bool valid = false;
char array[MAX_NAMES][MAX_LENGTH + 1];
for(int i = 0; i < MAX_NAMES; i++)
{
valid = false;
while(!valid)
{
cout << "enter a name" << endl;
char buffer[256];
cin >> buffer;
int len = strlen(buffer);
if(len <= MAX_LENGTH)
{
valid = true;
strcpy(array[i], buffer);
}
else
cout << "name too long " << endl;
}
}
for(int j = 0; j < MAX_NAMES; j++)
{
cout << array[j] << endl;
}
}
void displayarray(const char array[3][6],int r,int MAX_LENGTH)
{
for(int x=0;x< MAX_NAMES;x++)
{
cout<<"name["<<x<<"]";
for(int i=0;i<MAX_LENGTH;i++)
{
cout<<getname[x][i];///displaying error on thisline///
}
}
}
please help !!!