Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to get info from stdio? Pin
includeh1028-Jun-02 17:36
includeh1028-Jun-02 17:36 
AnswerRe: how to get info from stdio? Pin
Michael Dunn28-Jun-02 20:20
sitebuilderMichael Dunn28-Jun-02 20:20 
GeneralRe: how to get info from stdio? Pin
Mike Nordell30-Jun-02 0:20
Mike Nordell30-Jun-02 0:20 
GeneralRe: how to get info from stdio? Pin
includeh1030-Jun-02 21:06
includeh1030-Jun-02 21:06 
Generalfriend function problem ... Pin
Hadi Rezaee28-Jun-02 16:33
Hadi Rezaee28-Jun-02 16:33 
GeneralRe: friend function problem ... Pin
moswal28-Jun-02 17:46
moswal28-Jun-02 17:46 
GeneralMemory Context Memory Leak Pin
moswal28-Jun-02 16:08
moswal28-Jun-02 16:08 
GeneralCircular Queue Pin
JohnnyG28-Jun-02 14:55
JohnnyG28-Jun-02 14:55 
Can anyone provide an example of a circular queue in C? I've never used one before and researching on the net has shown a whole host of approaches of which I think have alot of overhead.

1) I don't want to and can't use STL since this is a C program.

2) All examples I've seen use data structures like a linked list with "next" pointers and one of the attributes is the data itself.

3) They also have all of the functions which add, delete, check for empty, etc. but I don't want to spend the time doing this for the reason specified below. I don't want to call functions but do this on the fly as I add or remove data from the queue.

4) I'm reading from a serial port at 115k baud in a read thread and don't have any time to format the data so I would like to do a memcopy to an array or circular buffer so it must be contiguous but then there is the wraparound problem I'm aware of. Worst case, a for loop. I will process or format the data into it's proper format in another thread which will access this circular queue as the read thread is putting data into it.

5) Shouldn't it be as simple as a char array of certain size with two char pointers; one to head and one to tail? I know how to see if the queue is empty but how do I detected overrun? If detecting overrun is simply is head > tail then what about when I wrap around to the beginning of the buffer?

Any code examples and suggestions would be appreciated.

John
GeneralRe: Circular Queue Pin
Ancient Dragon28-Jun-02 15:28
Ancient Dragon28-Jun-02 15:28 
GeneralRe: Circular Queue Pin
subtractive30-Jun-02 7:28
subtractive30-Jun-02 7:28 
GeneralRe: Circular Queue Pin
JohnnyG30-Jun-02 12:53
JohnnyG30-Jun-02 12:53 
GeneralOpaque Label Controls Pin
AndyO28-Jun-02 14:45
AndyO28-Jun-02 14:45 
GeneralWinCE Help Files Pin
Mel Stober28-Jun-02 12:27
Mel Stober28-Jun-02 12:27 
GeneralRe: WinCE Help Files Pin
Anders Molin29-Jun-02 3:03
professionalAnders Molin29-Jun-02 3:03 
GeneralMulti language Pin
orcun colak28-Jun-02 11:51
orcun colak28-Jun-02 11:51 
GeneralRe: Multi language Pin
Scott H. Settlemier29-Jun-02 6:20
Scott H. Settlemier29-Jun-02 6:20 
GeneralMessageBox problem - only flashes Pin
David Viggiano28-Jun-02 10:38
David Viggiano28-Jun-02 10:38 
GeneralRe: MessageBox problem - only flashes Pin
Jason Henderson28-Jun-02 16:24
Jason Henderson28-Jun-02 16:24 
GeneralHelp me>>>>>>>>>>>>>>>> Pin
Michael Liu28-Jun-02 8:36
Michael Liu28-Jun-02 8:36 
GeneralRe: Help me>>>>>>>>>>>>>>>> Pin
Mike Nordell28-Jun-02 8:46
Mike Nordell28-Jun-02 8:46 
GeneralRe: Help me>>>>>>>>>>>>>>>> Pin
Jason Henderson28-Jun-02 16:23
Jason Henderson28-Jun-02 16:23 
GeneralRe: Help me>>>>>>>>>>>>>>>> Pin
Christopher Lord28-Jun-02 20:45
Christopher Lord28-Jun-02 20:45 
GeneralProblem with Buttons in Child Windows Pin
AndyO28-Jun-02 7:34
AndyO28-Jun-02 7:34 
GeneralOnly one column in reportview listcontrol Pin
ns28-Jun-02 6:44
ns28-Jun-02 6:44 
GeneralRe: Only one column in reportview listcontrol Pin
Mike Nordell28-Jun-02 8:38
Mike Nordell28-Jun-02 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.