自定义malloc 函数错在哪呢?
程序代码:
#include "stdio.h"
#include "conio.h"
#include "string.h"
#define M 1000 //自定义malloc函数
#define NULL 0
char all[M];
char *a=all;
void * mall(int s)
{
static char *a=all;
if(s>0&&a+s<=all+M)
{
a=a+s;
return a-s;
}
return NULL;
}
int main()
{
char *str;
str=(char *)mall(5); //分配地址
gets(str);
printf("%s",str);
getch();
return 0;
}
[[it] 本帖最后由 bianfeng 于 2008-4-10 15:27 编辑 [/it]]


