ENG2309 Lab Week 9
2D-Arrays and Files Please ensure that your programs have correct formatting and comments. 1. Write a C program which creates a 3x6 array of integers and then uses nested loops to read the required 18 values from the keyboard. A second series of nested loops should then be used to display the array in matrix style to the screen. Your output should look as follows, with tabs between each number: 6 2 7 2. 3 0 2 -1 4 -6 5 2 28 8 13 1 7 10 0

Write a C program that reads strings from the user (maximum length of 20) and stores these in an array of strings. The program should stop reading strings when either 30 in total have been read, or the string “.” is read. The terminating “.” string should not be stored in the array. Once all strings are stored, use a loop to print each string to the screen, 1 per line. Modify the program from question 2 such that the strings are written to the file “output.txt” instead of to the screen. Write a C function called longest_string which takes as input an array of strings (max string length 20) and the number of strings in the array, then returns the index position of the longest string. Then modify the main program from question 2 so that the array of strings is passed to this function, and the longest string only, plus its length, is printed to the screen. A retailer uses a very simple database system to store prices, barcode numbers and names for each of its products. This database is stored in a text file in the format: barcode1 price1 name1 barcode2 price2 name2 … where the barcode is simply an int, and the price a float. Note that the name may contain spaces, so the entire line is used. Write a C program which reads such a database from a file (filename to be entered from the user), and displays the list of products to the screen in a user-friendly format. Your program should perform error checking to ensure that each of the numerical fields is read correctly and the formatting of the file is correct. (Hint:...