Circular buffer: Difference between revisions

Content deleted Content added
m Undid edits by 2407:C00:6004:3D05:6CA6:2BF8:78ED:B522 (talk) to last revision by BrownHairedGirl
m improved style in the code example, changed a useless comment and corrected a constant definition. The entire section and the code example remains incorrect and misleading and I shall fix it fully if I find the time
Line 68:
 
<syntaxhighlight lang="c">
#define BUFLEN 3
enum {N = 3};
int buf[N]; // N elements circular buffer
int end = 0; // write index
int start = 0; // read index
 
int buf[NBUFLEN]; /* array //to Nbe elementstreated as circular buffer */
void put(int item) {
int end = 0; //* write index */
buf[end++] = item;
int start = 0; //* read index */
end %= N;
 
void put(int item) {
{
buf[end++] = item;
end %= N;
}
 
int get()
{
int item = buf[start++];
start %= N;
return item;
}
</syntaxhighlight>