#include <stdio.h>
#define max 1000
#define NULL 0
char memory[max];
char *start;
void *MyGetBLock(int nBytes);
main()
{
char *pos;
int n;
clrscr();
start=memory;
while(1)
{
printf("How many Bytes do you want?end by -1./n");
scanf("%d",&n);
if(n==-1)
break;
pos=MyGetBLock(n);
if(pos==NULL)
{
printf("Error:No memory available./n");
break;
}
else
printf("your memory %ld is from %ld to %ld./n",(long)memory,(long)pos,(long)(start-1));
}
getch();
}
void *MyGetBLock(int nBytes)
{
char *pos;
if((start+nBytes)>(memory+max-1))
return NULL;
pos=start;
start+=nBytes;
return (pos);
}