函数指针地址

 ̄綄美尐妖づ 提交于 2019-12-05 01:52:53

/*strlen函数:返回字符串s长度*/
int strlen(char *s)
{
 int n;
 for(n=0;*s!='\0';s++)
  n++;
 return n;
}

#define ALLOCSIZE 10000 /*可用空间大小*/
static char allocbuf(ALLOCSIZE); /*alloc使用的存储区*/
static char *allocp=allocbuf;  /*下一个空闲位置*/
char *alloc(int n)     /*返回指向n个字符的指针*/
{
 if(allocbuf+ALLOCSIZE-allocp>=n) /*有足够的空闲空间*/
 {
  allocp+=n;
  return allocp-n;   /*分配前的指针p*/
 }else       /*空闲空间不够*/
 return0;

void afree(char *p)     /*释放p指向的存储区*/
{
 if(p>=allocbuf&&p<allocbuf+ALLOCSIZE)
  allocp=p;
}
 
 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!