Submission Instructions:1. For each problem, submit1)your program, and2)screenshots (jpg or pngformat) of the execution (command line and output) of the program. The screenshots show that your program...

1 answer below »


Submission Instructions:


1. For each problem, submit
1)
your program, and
2)
screenshots (
jpg or png
format) of the execution (command line and output) of the program. The screenshots show that your program produces correct results. Include only the executions. Don't include the output of gcc compilation in the screenshots. You must submit C programs (not C++, java, etc), which can be compiled using gcc on the virtual machine used in the course. Alsotest your program on the virtual machine. The grader will not give credits if your program cannot be compiled or run on the virtual machine.


2. Name your programs using the pattern HW9_Problem#.c , and name your screenshots using the pattern HW9_Problem#_Index.jpg. Problem# is the problem number (e.g., 1, 2, 3, 4, etc). Index is the index number showing the order of the screenshots (e.g., 1 or 2).


3. Submitindividual files.DO NOT SUBMIT A ZIP FILE.




Microsoft Word - File Access and Directory Traversal.docx CS288 Intensive Programming in Linux DO NOT DISTRIBUTE WITHOUT WRITTEN PERMISSION FROM PROF. XIAONING DING Problem 1: Reading/Writing Files in Binary and Text Format (30 points) Implement TWO C programs. The first program receives integers from user inputs, and saves a copy of the integers into a text file and the other copy into a binary file. The second program receives indexes from user input, finds the corresponding integers from the text file and binary file, and prints out the integers. For example, when you run the first program and provide the following integers, the program will generate two files. (If the files already exist, the program needs to truncate them before writing new data into the files. If the files did not exist, create them.) One file is a text file (e.g., you can name it numbers.txt). You may choose to save each number on each line or to use a special character to separate the integers. You can verify that it is really a text file by printing out the first part (e.g., head -c 100 ./numbers.txt). The other file is a binary file (e.g., you can name it numbers.bin), with each integer taking 4 bytes. You can hard-code the file names in your program. Input data 1 : 5 Input data 2 : 126 Input data 3 : 37 … Input data 100 : 3794 Input data 101 : 794 … Input data 200 : 74 Input data 201 : 94 User can press ctrl-d to stop the input (scanf() returns EOF). Then, if you run the second program and provide the following indexes, the program will print out the corresponding integers saved in the two files. Input index: 100 Integer saved in text file: 3794 Integer saved in binary file: 3794 Input index: 200 Integer saved in text file: 74 Integer saved in binary file: 74 Input index: 2 Integer saved in text file: 126 Integer saved in binary file: 126 I know the integers that the second program reads from the two files are the same. The program is for practice. For each index, your program MUST read a separate integer from each file, and CANNOT reuse/copy the integer read from one file as if it was from the other file. But, you are encouraged to this trait to verify that your program is correct --- if the two numbers are different, there must be some bugs. The second program needs to assume that the files may be too large to be read into memory completely. (This often happens! Consider bigdata processing and scientific computing, which often generate terabytes CS288 Intensive Programming in Linux DO NOT DISTRIBUTE WITHOUT WRITTEN PERMISSION FROM PROF. XIAONING DING of data). Thus, it’s not realistic to send up an array and read all the integers from a file into the array. Instead, it needs to use fseek and/or rewind to change file offsets based on index and then read into the integers. Submission Instructions Submit individual files following the instructions below. DO NOT SUBMIT A ZIP FILE. • Your C programs: Name your programs problem1_write.c and problem1_read.c. • 1~2 screenshots in jpg format for each program showing that your program really works: Name your screenshots using the pattern problem1_index.jpg. Index is 1, 2, or, 3… • 1 screenshot in jpg format to show that one of the files is in text format (head -c 100 ./numbers.txt). Testing Test your program manually first. The numbers printed out by the second program should match those provided to the first program. Also, check the sizes of the files (numbers.txt and numbers.bin). Which uses more space? To fully test your program with more integers, modify and use the following scripts. $1 of the script is the number of the integer values. $2 is the number of indexes. You need to inspect the output of the second program. Take screenshots when you test your program manually, such that we can see the numbers provided to the program and the output of the program. #!/bin/bash count=$1 echo "================== Writing files ======================" for (( i=0; i<${count}; i++="" ));="" do="" echo="" $random="" done="" |="" path_name_of_your_1st_program="" ls="" –l="" ./numbers.txt="" ./numbers.bin="" echo="" "="=================" reading="" files="====================="" for="" ((="" i="0;"><$2; i++="" ));="" do="" echo="" $(($random="" %="" ${count}))="" done="" |="" path_name_of_your_2st_program="" problem="" 2:="" traverse="" a="" directory="" (70="" points)="" write="" two="" c="" programs.="" the="" programs="" print="" out="" the="" pathnames="" of="" all="" the="" files="" in="" a="" directory,="" including="" all="" the="" files="" under="" all="" the="" sub-directories,="" sub-sub-directories,="" etc.="" (i.e.,="" sub-directories="" at="" all="" the="" levels).="" the="" pathnames="" should="" be="" printed="" out="" in="" order="" of="" file="" sizes="" with="" the="" pathname="" of="" the="" smallest="" file="" on="" top="" (i.e.,="" ascending).="" one="" use="" recursion="" and="" one="" does="" not="" use="" recursion.="" submission="" instructions="" submit="" individual="" files="" following="" the="" instructions="" below.="" do="" not="" submit="" a="" zip="" file.="" •="" your="" c="" programs:="" name="" your="" programs="" problem2_resursive.c="" and="" problem2_nonresursive.c.="" cs288="" intensive="" programming="" in="" linux="" do="" not="" distribute="" without="" written="" permission="" from="" prof.="" xiaoning="" ding="" •="" 1~2="" screenshots="" in="" jpg="" format="" for="" each="" program="" showing="" that="" your="" program="" really="" works:="" name="" your="" screenshots="" using="" the="" pattern="" problem2_recursive_index.jpg="" or="" problem2_nonrecursive_index.jpg="" .="" index="" is="" 1,="" 2,="" 3…="" •="" 1="" screenshot="" in="" jpg="" format="" to="" show="" the="" difference="" between="" the="" two="" programs.="" on="" the="" screenshot,="" highlight="" or="" circle="" the="" code="" that="" does="" the="" recursion.="" you="" may="" use="" diff="" to="" get="" the="" differences="" and="" then="" take="" a="" screenshot.="" name="" your="" screenshot="" problem2_diff.jpg="" diff="" problem2_resursive.c="" problem2_nonresursive.c="" objectives="" •="" to="" learn="" how="" to="" traverse="" a="" directory="" •="" to="" learn="" how="" to="" check="" file="" status="" •="" to="" gain="" more="" experience="" on="" using="" pointers="" and="" linked="" lists="" •="" to="" gain="" more="" experience="" on="" sorting="" a="" linked="" list.="" •="" to="" learn="" how="" to="" write="" recursive="" functions="" •="" to="" learn="" how="" to="" test="" a="" program.="" requirements="" and="" instructions="" •="" your="" program="" should="" take="" one="" argument,="" which="" is="" the="" pathname="" of="" the="" directory.="" (important!="" if="" you="" don't="" follow="" strictly,="" we="" may="" not="" be="" able="" to="" run="" your="" program="" correctly,="" and="" you="" may="" get="" lower="" grades.)="" for="" example,="" the="" following="" command="" sorts="" the="" files="" under="" directory="" usr/share/man:="" ./your_program="" usr/share/man="" •="" all="" files="" directly="" and="" indirectly="" under="" the="" directory="" should="" be="" considered.="" this="" means="" that="" your="" program="" needs="" to="" traverse="" the="" sub-directories,="" sub-sub-directories,="" sub-sub-sub-directories,="" etc,="" and="" check="" the="" files="" there.="" for="" example,="" when="" your="" program="" is="" run="" against="" directory="" dir="" on="" the="" right,="" all="" 5="" files="" (file="" 1="" ~="" file="" 5)="" should="" be="" included.="" •="" for="" an="" implementation="" without="" using="" recursion,="" use="" a="" linked="" list="" to="" organize="" the="" sub-directories="" that="" have="" not="" been="" scanned.="" refer="" to="" the="" slides="" on="" directory="" traversal="" in="" the="" bash="" part.="" the="" slides="" on="" state="" space="" search="" can="" also="" give="" you="" some="" ideas.="" •="" assume="" the="" longest="" pathname="" does="" not="" exceed="" 1024="" single-byte="" characters.="" •="" for="" the="" files="" with="" the="" same="" size,="" there="" is="" no="" requirement="" on="" how="" their="" pathnames="" should="" be="" sorted.="" •="" print="" out="" the="" results="" on="" the="" screen="" in="" text="" format,="" one="" line="" for="" each="" file="" with="" file="" size="" followed="" by="" a="" tabular="" symbol="" ('\t')="" and="" the="" file="" pathname.="" programs="" using="" different="" formats="" in="" outputs="" will="" fail="" the="" tests="" and="" lead="" to="" lower="" grades.="" dir="" sub-dir="" 1="" sub-dir="" 2="" file="" 1="" subsub-dir="" 1="" subsub-dir="" 2="" file="" 2="" file="" 4="" file="" 5="" file="" 3="" cs288="" intensive="" programming="" in="" linux="" do="" not="" distribute="" without="" written="" permission="" from="" prof.="" xiaoning="" ding="" the="" sample="" output="" when="" the="" program="" is="" run="" with="" the="" command="" below="" against="" directory="" usr/share/man/="" is="" shown="" as="" follows:="" $./your_program="" usr/share/man="" 30="" usr/share/man/man1/cpp-4.8.1.gz="" 30="" usr/share/man/man1/cpp-5.1.gz="" 30="" usr/share/man/man1/gcc-4.8.1.gz="" 30="" usr/share/man/man1/gcc-5.1.gz="" 35="" usr/share/man/man3/xaudisposeauth.3.gz="" 35="" usr/share/man/man3/xaufilename.3.gz="" 35="" usr/share/man/man3/xaugetauthbyaddr.3.gz="" …="" 86618="" usr/share/man/man1/bash.1.gz="" 104755="" usr/share/man/man5/smb.conf.5.gz="" 287622="" usr/share/man/man1/x86_64-linux-gnu-gcc-6.1.gz="" 303306="" usr/share/man/man1/x86_64-linux-gnu-g++-7.1.gz="" 303306="" usr/share/man/man1/x86_64-linux-gnu-gcc-7.1.gz="" testing="" •="" check="" whether="" the="" program="" can="" print="" out="" correct="" result="" when="" it="" is="" run="" against="" a="" directory="" containing="" a="" few="" files="" with="" different="" sizes="" step="" 1.="" create="" a="" directory="" and="" a="" few="" files="" in="" the="" directory="" mkdir="" ./test1="" dd="" if="/dev/zero" of="./test1/file1" bs="10" count="1" dd="" if="/dev/zero" of="./test1/file2" bs="100" count="1" dd="" if="/dev/zero" of="./test1/file3" bs="1000" count="1" step="" 2.="" execute="" the="" program="" against="" ./test1:="" ./your_program="" ./test1="" step="" 3.="" check="" the="" output="" of="" the="" program,="" which="" should="" look="" like="" 10="" ./test1/file1="" 100="" ./test1/file2="" 1000="" ./test1/file3="" •="" check="" whether="" the="" program="" can="" print="" out="" correct="" result="" when="" it="" is="" run="" against="" a="" directory="" containing="" sub-directories="" and="" regular="" files="" in="" sub-directories="" step="" 1.="" create="" a="" directory="" and="" a="" few="" files="" in="" the="" directory="" mkdir="" ./test2="" dd="" if="/dev/zero" of="./test2/file1" bs="10" count="1" dd="" if="/dev/zero" of="./test2/file2" bs="100" count="1" mkdir="" ./test2/dir1="" dd="" if="/dev/zero" of="./test2/dir1/file3" bs="20" count="1" dd="" if="/dev/zero" of="./test2/dir1/file4" bs="200" count="1" mkdir="" ./test2/dir2="" dd="" if="/dev/zero" of="./test2/dir2/file5" bs="30" count="1" cs288="" intensive="" programming="" in="" linux="" do="" not="" distribute="" without="" written="" permission="" from="" prof.="" xiaoning="" ding="" dd="" if="/dev/zero" of="./test2/dir2/file6" bs="300" count="1" mkdir="" ./test2/dir3="" dd="" if="/dev/zero" of="./test2/dir3/file7" bs="40" count="1" dd="" if="/dev/zero" of="./test2/dir3/file8" bs="400" count="1" step="" 2.="" execute="" the="" program="" against="" ./test2:="" ./your_program="" ./test2="" step="" 3.="" check="" the="" output="" of="" the="" program,="" which="" should="" look="" like="" 10="" ./test1/file1="" 20="" ./test1/dir1/file3="" 30="" ./test1/dir2/file5="" 40="" ./test1/dir3/file7="" 100="" ./test1/file2="" 200="" ./test1/dir1/file4="" 300="" ./test1/dir2/file6="" 400="" ./test1/dir3/file8="" •="" check="" whether="" the="" program="" can="" print="" out="" correct="" result="" when="" it="" is="" run="" against="" a="" large="" directory,="" such="" as="" usr/share/man.="" step="" 1.="" run="" the="" program="" and="" redirect="" the="" result="" into="" a="" file="" output_test.txt="" ./your_program="" usr/share/man=""> output_test.txt Step 2. Check whether the sizes are correctly sorted in the output. If they are correctly sorted, you will not see diff print out any text. cut -f 1 output_test.txt > sizes_test.txt sort -s -n sizes_test.txt > sizes_test_sorted.txt diff sizes_test.txt sizes_test_sorted.txt Step 3. Check whether the output includes the pathnames of all the files --- the output should have 9000+ lines.
Answered Same DayNov 19, 2022

Answer To: Submission Instructions:1. For each problem, submit1)your program, and2)screenshots (jpg or...

Aditi answered on Nov 20 2022
38 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here