Hi,
Hope you all are great there??
Well apologies for the last posts, also thanks Malc for telling the rule.
I am new to the forum, also this is the first time I had joined any forum and I have joined it because I like the rule of it that it doesn't make the other user copy the stuff but help them where they get stuck.
Despite of teaching English it is a very good forum and if everyone have problem reading my Post, kindly don't.
Anyways, I am new to programming and I hope this forum will help me where i get stuck
so here is my code as i said once the assignment due date is over i will post it:
The only problem i get is when the user enter an alphabet, the programme is not running properly instead it get stucked in the loop.Code:#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main ()
{
int i, n;
int *pointerData;
clrscr();
cout<<"Enter the size of the array: ";
cin>>i;
if(!isalpha(i))
{
pointerData = (int*) calloc (i,sizeof(int));
if (pointerData==NULL)
{
cout<<"Unable to allocate memory for array."<<endl;
return 0;
}
for (n = 0; n < i; n++)
{
cout<<"Enter number: ";
cin>>pointerData[ n ];
}
cout<<"The elements of the array are:"<<endl;
for (n = 0; n < i; n++)
cout<<pointerData[ n ]<<" ";
pointerData =(int*) realloc(pointerData, 2 * i * sizeof(int));
if (pointerData==NULL)
{
cout<<"Unable to re-allocate memory for array."<<endl;
return 0;
}
cout<<""<<endl<<"Enter the elements in the array after reallocation:"<<endl;
for (n = i; n < i*2; n++)
{
cout<<"Enter number: ";
cin>>pointerData[ n ];
}
cout<<endl;
for (n = 0; n < i*2; n++)
cout<<pointerData[ n ]<<" ";
free (pointerData);
}
getch();
return 0;
}
I hope anybody can help me out in this regard.
Apologies in advance for English grammar.
Regards