问题遇到的现象和发生背景
汽车报警装置csapp实验
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h> //This is useful to do i/o to test the code
unsigned int driver_on_seat;//1//
unsigned int doors_closed;//4//
unsigned int bell;//1//
void read_inputs_from_ip_if(){
driver_on_seat=1;
doors_closed=1;
unsigned int driver_seat_belt_fastened=1;//2
unsigned int engine_running=1;//3
unsigned int key_in_car=1;//5
unsigned int door_lock_lever=1;//6
unsigned int brake_pedal=1;//7
unsigned int car_moving=1;//8
unsigned int door_lock;//2
unsigned int brake;//3
//place your input code here
//to read the current state of the available sensors
}
void write_output_to_op_if(){
printf("The state of the 3 actuators (DLA/BELL/BA) is: \n");
printf("%x, %x, %x.\n", door_lock, bell, brake);
//place your output code here
//to display/print the state of the 3 actuators (DLA/BELL/BA)
}
//The code segment which implements the decision logic
void control_action(){
if (driver_on_seat && !doors_closed)
bell = 1;
else if (!driver_seat_belt_fastened && engine_running)
bell = 1;
else bell = 0;
if (!driver_on_seat && key_in_car)
door_lock = 0;
else door_lock = 1;
if (brake_pedal && car_moving)
brake = 1;
else brake = 0;
}
int main(int argc, char *argv[])
{
for (; ; )
{
read_inputs_from_ip_if();
control_action();
write_output_to_op_if();
}
return 0;
}
运行结果及报错内容
我想要达到的结果
成功运行,找到错误原因