Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

File I/O The object of this exercise is to read data from a file and populate an array of structs, print the information, and then

image text in transcribed

File I/O The object of this exercise is to read data from a file and populate an array of structs, print the information, and then add one more struct to the file. The struct will be the same polygon struct that you worked on last week. The format of the text file is as follows: 30211.0000003.0000004.000000 The first line in the program says how many polygons are in the file. Each subsequent line has two numbers corresponding to each polygon. The first number indicates what type of polygon it is -0 for Triangle, 1 for Square, and 2 for Pentagon. The second number is the side length of the polygon. Writing the program Start with the program from last week and modify the code that gets the polygons from the user and instead change it so that it gets it from the file. You can keep the code that prints the polygon data and calculates the area. The filename should be input on the command line. The example code video on HuskyCT should help you with this part of the program. The user can optionally enter a second argument on the command line. If that second argument is there, write out the polygon information to that file using fprintf. The program will be executed as follows: . /lab7 lab7-polygons.txt new.txt where lab7-polygons. txt is the name of the file containing the data. This file has been provided for you on HuskyCT. Since the second argument new. txt is there, the polygon data will be output to that file. If everything works, the new. txt file should be exactly the same as the lab7polygons. txt file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions