Making use of queue.c

This is a discussion on Making use of queue.c within the C Programming forums, part of the General Programming Boards category; I am working on a program that uses interrupts and a buffer to read/write characters from/to the console screen. (This ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    12

    Making use of queue.c

    I am working on a program that uses interrupts and a buffer to read/write characters from/to the console screen. (This is a tty.c program with ttywrite(), ttyread(), ect...)

    I also have a given queue folder, which contains queue.c that has the methods:

    Code:
     int init_queue(Queue *q, int max_chars);  make a new empty queue, filling in *q
     int enqueue(Queue *q,char ch);                enqueue char ch on q, or return -1 if can't
     int dequeue(Queue *q);                            dequeue a char and return it, or return -1 if can't
     int queuecount(Queue *q);                       return # chars currently in queue q
    Along with queue.h, which mainly contains:

    Code:
    typedef struct queue {      
      char ch[MAXCHARBUF];         /* char contain in queue */
      int front;                              /* front index of queue */
      int rear;                              /* rear index of queue */
      int count;                          /* current numbers of element in queue */ 
      int max;                           /* actually use length */
    } Queue;
    along with some of the method headers and defined variables.

    In the separate file tty.c where I am hoping to replace the buffers with queues, how can I develop a queue struct atop of the program that allows me to make instances of queue.c?

    Also, there is already a struct:
    Code:
    struct tty ttytab[NTTYS] ;
    at the top of tty.c which I have been told is where I should put my Queue structs into.

    I am new to C (coming from C#/Java) and am lost trying to wrap my head around the logic.

    Any advice will be greatly appreciated, thanks
    Last edited by micmac700; 09-22-2006 at 10:16 AM.

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    Code:
    printf("USE CODE TAGS!");
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Practice with something like this
    Code:
    int main ( ) {
        Queue myqueue;
    
        init_queue( &myqueue, 10 );
        enqueue( &myqueue, 'h' );
        enqueue( &myqueue, 'e' );
        printf( "%c\n", dequeue(&myqueue) );
        enqueue( &myqueue, 'l' );
        enqueue( &myqueue, 'l' );
        printf( "%c\n", dequeue(&myqueue) );
        enqueue( &myqueue, 'o' );
        printf( "%c\n", dequeue(&myqueue) );
        printf( "Current length=%d\n", queuecount(&myqueue) );
        printf( "%c\n", dequeue(&myqueue) );
        printf( "%c\n", dequeue(&myqueue) );
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop making duplicate threads.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Indeed - replies here
    Queue stuct - Please Help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  3. Replies: 2
    Last Post: 01-13-2003, 01:28 PM
  4. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21