[Error] base operand of '->' has non-pointer type 'stac

犯错=成长

编写顺序栈时出现下边的提醒

31[Error] base operand of '->' has non-pointer type 'stack'

直接上代码(错误版本):

#include <stdlib.h>
#include <stdio.h>
#define SIZE 1000
typedef struct{
    int data[SIZE];
    int top;
}stack; 


void Init(stack &s){//初始化棧,棧里面放的元素不一定是什么
   s.top=-1;    
} //初始化完成,各种参数也已经确定



void Push(stack &s,int e){
    if(s.top==SIZE-1)printf("已经满了~");
    else
    s.data[++(s.top)]=e;
} 


void  Pop(stack &s,int &e){
    if(s.top==-1)printf("没有元素,无法抛出!");
    e=s.data[(s.top)--];

}

void Print(stack &s){
    while(s.top!=-1)
    printf("%d",s.data[s.top--]);
}



int main(){
    stack s;
    Init(s);
    Push(s,2);
    Push(s,2);
    Push(s,2);
    Print(s);
   return 0;    
}
=============================================================

以下是正确版本:

#include <stdlib.h>
#include <stdio.h>
#define SIZE 1000
typedef struct{
    int data[SIZE];
    int top;
}stack; 


void Init(stack &s){//初始化棧,棧里面放的元素不一定是什么
   s.top=-1;    
} //初始化完成,各种参数也已经确定



void Push(stack &s,int e){
    if(s.top==SIZE-1)printf("已经满了~");
    else
    s.data[++(s.top)]=e;
} 


void  Pop(stack &s,int &e){
    if(s.top==-1)printf("没有元素,无法抛出!");
    e=s.data[(s.top)--];

}

void Print(stack &s){
    while(s.top!= -1)
    printf("%d",s.data[s.top--]);
}



int main(){
    stack s;
    Init(s);
    Push(s,2);
    Push(s,2);
    Push(s,2);  
    Print(s);
   return 0;    
}

反思:之前从来没有太注意 “.”以及”->”之间的区别,今天才发现有多么严重。”.”适用于结构体变量,”->”适用于结构体指针变量!!!!

还有,一定要记得初始化~## 标题 ##

  • 13
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
实验一 简单组合逻辑电路的设计 一 实验要求 用verilog HDL语言描写出简单的一位数据比较器及其测试程序; 用测试程序对比较器进行波形仿真测试;画出仿真波形; 总结实验步骤和实验结果。 二 实验原理与内容 这是一个可综合的数据比较器,很容易看出它的功能是比较数据a与数据b,如果两个数据相同,则给出结果1,否则给出结果0。在Verilog HDL中,描述组合逻辑时常使用assign结构。注意equal=(a==b)?1:0,这是一种在组合逻辑实现分支判断时常使用的格式。 模块源代码 测试模块: Verilog-实验报告全文共8页,当前为第1页。 Verilog-实验报告全文共8页,当前为第1页。 波形图: 四 结实验步骤和实验结果 由图可看出,每当输入的电位值不同时输出为0,这与实验要求一致,相同时输出为1,故此程序是可行的。 Verilog-实验报告全文共8页,当前为第2页。 Verilog-实验报告全文共8页,当前为第2页。 实验三 在verilog HDL中使用函数 一 实验要求 掌握函数在模块中的使用 用测试程序进行波形仿真测试;画出仿真波形 总结实验步骤和实验结果 二 实验原理与内容 与一般的程序设计语言一样;verilog HDL也可以使用函数已是应对不同变量采取同一运算的操作。verilog HDL函数在综合时被理解成具有独立运算功能的电路,每调用一次函数相当于改变这部分电路的输入以得到相应的计算结果。 模块源代码: module ex3(clk,n,result,reset); output[31:0] result; input[3:0] n; input reset,clk; reg[31:0] result; always @(posedge clk) begin if(!reset)result <= 0; else begin result <= n*factorial(n)/((n*2)+1); end end function[31:0] factorial; input[3:0] operand; reg[3:0] index; begin factorial = operand ? 1:0; for(index = 2;index <= operand;index = index+1) factorial = index*factorial; end endfunction endmodule `timescale 1ns/100ps `define clk_cycle 50 module ex3_t(); reg[3:0] n,i; Verilog-实验报告全文共8页,当前为第3页。 reg reset,clk; Verilog-实验报告全文共8页,当前为第3页。 wire[31:0] result; initial begin n=0; reset=1; clk=0; #100 reset=0; #100 reset = 1; for(i=0;i <= 15;i=i+1) begin #200 n=i; end #100 $stop; end always #`clk_cycle clk =~ clk; ex3 ex30(.clk(clk),.n(n),.result(result),.reset(reset)); always @(negedge clk) $display("at n=%d,result=%d",n,result); endmodule 波形图 : Verilog-实验报告全文共8页,当前为第4页。 Verilog-实验报告全文共8页,当前为第4页。 实验四 在verilog HDL中使用任务 一 实验要求 掌握任务在结构化verilog HDL设计中的应用 用测试程序进行波形仿真测试;画出仿真波形 总结实验步骤和实验结果 二 实验原理与内容 仅有函数并不能满足verilog HDL中的运算需求。当我们希望能够将一些信号进行运算并输出多个结果时,采用函数结构就显得非常不方便,而任务结构在这方面的优势十分的突出。任务本身并不返回计算值,但是它通过类似C语言中形参与实参的数据交换,非常快捷的实现运算结果的调用。 模块源代码: output[3:0] ra,rb,rc,rd; input[3:0] a,b,c,d; reg[3:0] ra,rb,rc,rd; reg[3:0] va,vb,vc,vd; always @(a or b or c or d) begin {va,vb,vc,vd} = {a,b,c,d}; sort2(va,vc); sort2(vb,vd); sort2(va,vb); sort2(vc,vd); sort2(vb,vc); {ra,r

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱码仕1024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值