omg im am so confused right now
what is wrong here and what can i do to fix it
EDIT: omg i am so sorry…i am just so fluctuated right now that i cant even ask a question
i want to assign 10 inputed char strings to a pointer array.
using namespace std;
int main(int argc, char *argv[])
{
char *mess[10];
int i = 0;
for (; i < 10; i++)
{
cout << "Enter a string: ";
cin.getline(mess[i], 80);
}
for (i = 0; i < 10; i++)
cout << mess[i];
system("PAUSE");
return EXIT_SUCCESS;
}
What you want is probably declare your array this way:
As you are reading up to 80 characters from getline.
Your current implementation builds an array of 10
char*which are never initialized to point on allocated buffers.A much safer way would be to use
std::stringas the buffer size will be handled for you. A simple change to:Should give you what you want.
EDIT
If you absolutely need
char *(which is not a good idea), here’s what you’re looking for: