C语言新手求助一段代码的问题
# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>
struct Array
{
int len;
int cnt;
int * pbase;
};
void arr_inti(struct Array * pArr,int length);
void arr_show(struct Array *);
bool is_empty(struct Array *);
bool append(struct Array * pArr,int a);
bool is_full(struct Array * pArr);
int main(void)
{
struct Array arr;
arr_inti(&arr,2);
append(&arr,1);
append(&arr,1);
arr_show(&arr);
return 0;
}
void arr_inti(struct Array *pArr,int length)
{
pArr->pbase=(int *)malloc(sizeof(int)*length);
if (NULL==pArr->pbase)
{
printf("内存已满!\n");
}
else
{
pArr->len=length;
pArr->cnt=0;
}
return;
}
void arr_show(struct Array * pArr)
{
if(is_empty(pArr)==1)
{
printf("This array is empty!\n");
}
else
{
for(int i=0;i<pArr->cnt;++i)
{
printf("%d\n",pArr->pbase[i]);
}
}
}
bool is_empty(struct Array * pArray)
{
if(pArray->cnt==0)
return true;
else
return false;
}
bool append(struct Array * pArr,int a)
{
if(is_full(pArr)==1)
return false;
pArr->pbase[pArr->cnt]=a;
(pArr->cnt)++;
return true;
}
bool is_full(struct Array * pArr)
{
if(pArr->cnt=pArr->len)
return true;
else
return false;
}
如上,最后输出的值是随机值,然而我明明用apend函数赋值了呀?