Lab07_CS262F23

pdf

School

George Mason University *

*We aren’t endorsed by this school

Course

262

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

2

Uploaded by bananaticks

Report
1/2 CS262, Lab 07: File I/O and Formatting Due: Sunday, Oct 22 at 11:59 pm ET Description: In this assignment you will open text files for reading and writing and also will apply formatting to print information. It is important to have the basics of the fopen() , fclose() functions, and knowledge of the conversion characters needed for the different datatypes. If you use the fgets() function to read the input file, instead of stdin , the third parameter is a pointer to FILE (the return value of the fopen() function) Instructions: The source file for this assignment will be named lab7_<username>_<labsection>.c When running your program, you will enter the name of the input and output files on the command line . These filenames must be given, otherwise show an Error Msg! and exit the program. Here is the command you should run when executing your program: lab7_<username>_<labsection> <input_file> <output_file> Where: <input_file> and <output_file> are the file names for reading and writing respectively. Your program will open the input file for reading, and open the output file for writing. The first row in the input file has an int value specifying the remaining number of rows to be read . Your program will use this int value to process the rest of the file. The remaining rows have 7 columns of data that will be read into 6 variables . Your program will read in each line using fgets() then parse it using sscanf() . There is a name field that uses a comma (,) as a delimiter. You will need to scan the first and last name into one string using the comma delimiter . Then write the output with the fields in a different order to the output file. The order of the data fields and their data type in the input file is: Gnum name semester course credits grade int string int string int float The order of the data fields in your output file should be: name Gnum grade course credits semester The data in the output file should be formatted as follows: The name is left justified, min. width 25 The Gnum is left justified, min. width 10 The grade should print 2 decimal places, left justified, min. width 8 The course is left justified, min. width 10 The credits are left justified, min. width 3 The semester is right justified, min. width 3
2/2 You must use the input file called lab7_input.txt provided with this assignment. Do not modify it in any way. A similar input file will be used to test your program. Be sure to include comments within your code that explain in high-level terms what the various parts of your code are doing. Makefile: Modify the Makefile you used for lab6 so that it works for this assignment Submission: You will submit a typescript file similar to the one of previous Labs: 1. Create a typescript file named lab7_typescript_<username>_<labsection> 2. Show that you are logged onto Zeus 3. Show a listing of your directory 4. Show a listing of your code 5. Remove the executable using your Makefile 6. Compile your code with Makefile 7. Run the code given these options each in a separate run: lab7_<username>_<labsection> lab7_<username>_<labsection> input.txt lab7_<username>_<labsection> lab7_input.txt lab7_output.txt 8. Remove the executable using your Makefile 9. End the typescript 10. Be sure your directory ONLY contains the source file, script and Makefile 11. Verify your typescript file is correct, then change ( cd ) to the directory above 12. Create a tarfile of your directory 13. Submit the tarfile to Blackboard 14. Verify that your submitted tarfile can be extracted and it’s the right tarfile . Congratulations! You have completed your Lab assignment J
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help