Here is my code:
int main ()
{
const int MAX = 10;
char *buffer = nullptr; // used to get input to initialize numEntries
int ARRAY_SIZE = 20; // default is 20 entries
int numEntries;
success = false;
while (!success)
{
delete buffer;
buffer = nullptr;
buffer = new char [MAX];
cout << "How many data entries:\t";
cin.getline(buffer, MAX, '\n');
cout << endl << endl;
while (*buffer)
{
if (isdigit(*buffer++))
success = true;
else
{
success = false;
break;
}
}
}
numEntries = atoi(buffer);
The problem is that when I enter a any number, it just displays "numEntries = 0", and it crashes if I enter a string.
Can someone explain what exactly is happening?