C语言新手求助一段代码的问题

qq_33046541 qq_33046541 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
# 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函数赋值了呀?
...全文

相关推荐

C语言新手入门代码练习

本文档适合刚入手c的小伙伴,里面有鄙人做的练习题,难易不等以供学习

嘣嘣吧啦吧啦嘣

c语言新手问题答案

一个C新人提的10个问题的答案,总结了一下。

青葱岁月不可追

一段女生写的C语言代码(搞笑) - -

#include "stdio.h" #include "stdlib.h" result love(boy, girl) {   if ( boy.有房() and boy.有车() )    {     boy.set(nothing);     return girl.嫁给(boy);   }   if ( girl.愿意等() )   {    while( ! (boy.赚钱 > 100,000 and girl.感情 > 8 ) )    {     for ( day=1; day <=365; day++)     {      if ( day == 情人节 )      if ( boy.givegirl(玫瑰) )       girl.感情++;       else        girl.感情--;         if( day == girl.生日)      if ( boy.givegirl(玫瑰) )         girl.感情++;         else         girl.感情--;       boy.拼命赚钱();       }      }     if ( boy.有房() and boy.有车() )    {    boy.set(nothing);  return girl.嫁给(boy);  }    年龄++;    girl.感情--;    }   return girl.goto( another_boy); }

yjmfendou

c语言表白代码

c语言表白代码。有兴趣的可以参考下。谢谢

z1039565

银行利率问题——C语言代码

课程的随堂作业,C语言的,用dev就能运行,萌新代码,勿喷,仅仅帮助不想写作业的朋友方便一下,反正老师也不会仔细检查的

DTcode7
评论 2
收藏 已收藏
分享
返回顶部
qq_33046541
C语言 70,040 成员 243,237 内容