


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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Instructions for quiz #2 in cis 361, which includes writing a c program to randomly select a line from a file and output the second field, as well as decoding an unsigned int using a specific bit scheme. The document also includes an example of encoding and decoding characters using this bit scheme.
Typology: Quizzes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Name: Last, First March:
A. [128 points] Write a complete C program like what I’ve been using in lectures to randomly choose people to call on. (Your program here does not need to do everything like mine; in particular, your program does not need to modify any ‘count’ values in the data file.) A data file for your program here would appear like the following:
count name ===== ==== 13 BROWN,TERRY 14 JONES,SAM 12 LEE,CHRIS 13 SMITH,PAT
.. .. ..
Your program needs to skip over the header-material at the beginning of the file (through the line beginning with “=”, which you explicitly need to check for because the number of header lines can vary, not being just 2), randomly and fairly select one of the remaining lines, and output the second field of the selected line — “LEE,CHRIS” or “BROWN,TERRY” or... (Don’t worry about finding a line containing a low value.) The number of lines in the file needs to be determined by reading the file; it cannot be determined any other way. And then after that, without opening the file again, you’ll need to return to the beginning of it to re-find a selected line.∗^ (Do not try to store the entire contents of a file in memory.) Error-check program-arguments and file-access as usual, using standard error output and setting the exit-status value as appropriate. Also, use fgets() for reading, and use a named constant for the size of your line-buffers.
∗Actually, as my program does, even without reopening the file, you can do the random, fair selection without needing to return to the beginning of the file. If you figure out how to do this, fine; but otherwise, you need to return to the beginning of the file.