This program checks if given string is in alphabetical order and I am allocating new memory every time user enter a character but it is working fine if i don't allocate that memory Means (if i remove the commented line from the code below) is it a bug or some memory technique where is it getting memory from if i don't use that realloc()
line
#include<iostream>
#include<conio.h>
#include<stdlib.h>
bool Alphabetical(char DA[],unsigned short n)
{
for(n ;n>-1;n--)
if(n==0) return true;
else if((DA[n]<91&&DA[n-1]<91)&&(DA[n]<DA[n-1])) return false;
else if((DA[n]>96&&DA[n-1]>96)&&(DA[n]<DA[n-1])) return false;
else if((DA[n]<91&&DA[n-1]>96)&&(DA[n]+=32)&&(DA[n]<DA[n-1])) return false;
else if((DA[n]>96&&DA[n-1]<91)&&(DA[n]-=32)&&(DA[n]<DA[n-1])) return false;
return true;
}
int main()
{
int block=1,i=-1;
char *DA=(char*)malloc(1*block),c;
std::cout<<"Enter a string(ONLY ALPHEBATS,ANY LENGTH)\n";
while((c=getche())!=13)
if(c>64&&c<91||c>96&&c<123)
{
DA[++i]=c;
realloc(DA,1*(++block));/// i din't understand why is it working fine without this line
}
else std::cout<<"\b \b";
std::cout<<"\nreturned "<<Alphabetical(DA,i);
}