


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information about assignment 4 for the cs201 course in winter 2008. The assignment involves modifying a simple c program to read from an optional command-line argument, creating and writing to a binary file, and reading from that file. Students are required to use the original while loop and not change any existing code. The document also includes grading criteria and deliverables.
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



#include <unistd.h> #define BUFFERSIZE 256 int main(int argc, char **argv) { int n; char buf[BUFFERSIZE];
while((n = read(STDIN_FILENO,buf, BUFFERSIZE)) > 0) write(STDOUT_FILENO, buf, n); }
Modify this program so that it takes an optional command line argument infile. If infile is given, then copy infile to standard output; otherwise do just what this program already does. The twist is that your program must use the original while loop (the last two lines of code in main ) for both cases. You are only allowed to insert code, you are not allowed to change any existing code. You can not write separate while loops for the two cases, and you can not change the value of any constants such as STDIN_FILENO.
For # 3, write a small test bed program with a main() function that inputs a command line from standard input, invokes mysystem() , and prints the exit status of the child process. Use the test bed to test your function with various command lines.
a. Initialize an array of 100 double precision floating point values such that A[n] = n b. Create a file and write the array to the file, not as character strings but as an array of 8-byte objects, just as they appear in memory. You don't have to know what these objects look like, you only have to write them to a file. You can think of this file as containing a sequence of 100 records, each of size 8 bytes and each containing a binary floating point value. c. Seek to the thirty-fourth record in the file; that is, the one whose value is 34.0, and read that record into a double precision variable.
d. Print the value of that variable as a string to the standard output, using printf. e. The program must take one command line argument, specifying the name of the file to create. f. Do not use the Rio package. You may use Unix system calls or the stdio package to read and write the file.
Please read the Deliverables information on the homework page.
The assignment is worth a total of 50 points. Each item below indicates attributes the assignment should have, and points are deducted from 50 accordingly if those attributes are lacking.
Assignment submitted on time (50 points)
Assignment turned in correctly (up to 5 points each bullet)
Answer to problem #
Correctness of code, problem 2