#include <stdio.h>
#define BUF_CNT 10
int in=0;
int out=0;
int cnt=0;
char buf[BUF_CNT]={0};
void data_buff_init()
{
in = 0;
out = 0;
cnt = 0;
}
void data_in(char c)
{
if(cnt>=BUF_CNT)
{
out++;
if(out==BUF_CNT) out=0;
}
else
{
cnt++;
}
if(in>=BUF_CNT) in=0;
buf[in] = c;
in++;
}
char data_out()
{
char c = 255;
if(cnt>0)
{
if(out>=BUF_CNT) out=0;
c = buf[out];
out++;
cnt--;
}
return c;
}
int main()
{
char i = 0;
data_buff_init();
while(1)
{
for(i=0;i<20;i++)
data_in(i);
for(i=0;i<BUF_CNT;i++)
printf("%02x\r\n", data_out()&0x00ff);
break;
}
}
标签:cnt,buffer,CNT,C语言,char,环回,int,BUF,out
From: https://www.cnblogs.com/zengfeng1013/p/18059234