Write a program (in a single .c file) with a queue of strings implemented using array. You should write ite a queue type. The program reads a set of strings stored in a file (filename given on command line as argument) and inserts each string in the queue. Then it removes each string and writes it to another file (also given as second argument on command line).
filename: rollno_branch_batch_queuefile.c
Note: for this particular assignment, you must use open(), read(), write() calls and use of fopen(), fread(), etc functions is not allowed.
Hints:
* This problem involves some thinking about combinging the various different concepts about files, queues, data type implementation, array handling, etc.
* You have to implement a queue type which means, write the code for enqueue(), dequeue(), etc functions of the queue. This has to be done using an array and indexes as required, AND NOT using structures, pointers, and malloc as done in the class. You can refer to the way we've written stack.
* The program essentially copies a file into another. However before data goes from one file to another, it is temporarily stored in the queue of strings.
* The known functinos like read(), write() etc do not recognize strings. String is a char array terminated by NUL character. The read(), write() functions simply read some bytes from the file. So you will be required to process the data read from the file also.

I am sorry but we are not going to spoonfeed you for your assignments. Try out something and then ask speciific questions.

Note: If you want to write this program on MS-Windows os you may have to use _open(), _read(), and _close() instead of the functions specifid in your assignment. Also include header files io.h and fcntl.h

There are a couple ways you can write the program:

  1. Just use an array of char pointers and malloc() memory as the data is read from the file.

  2. Create a linked list of lines, assuming you have studied linked lists. This is the most efficient method because you don't have to know beforehand how many lines are in the file.

In either event, start out by reading the file one character at a time, putting each character into a char array whose size is just hard-coded in the program. When the line separator is reached (it will be either "\r\n", "\r" or "\n" depending on the operating system) add he new line to the array of linked list. Note that you will have to malloc() additional memory for this step.

After you get the above coded, compiled and tested you can begin working on the rest of the assignment.

Edited 4 Years Ago by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.