B
bintom
I want to dynamically allocate to memory to n names, each of 21
characters. I have written the followin code, but it gives the
following error message:
cannot convert `char (*)[21]' to `char**' in initialization
The full program is given below: Thanks in anticipation,
Bintom
#include <iostream.h>
int main()
{ int size, i;
cout << "How many names? ";
cin >> size;
char *cptr = new char[size][21];
for(i=0; i<size; i++)
{ cout << "Enter name " << i+1 << ": ";
cin.getline(*(cptr+i), 21);
}
for(i=0; i<size; i++)
cout << *(cptr+1) << "\n" ;
return 0;
}
characters. I have written the followin code, but it gives the
following error message:
cannot convert `char (*)[21]' to `char**' in initialization
The full program is given below: Thanks in anticipation,
Bintom
#include <iostream.h>
int main()
{ int size, i;
cout << "How many names? ";
cin >> size;
char *cptr = new char[size][21];
for(i=0; i<size; i++)
{ cout << "Enter name " << i+1 << ": ";
cin.getline(*(cptr+i), 21);
}
for(i=0; i<size; i++)
cout << *(cptr+1) << "\n" ;
return 0;
}