Question: 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
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 labc
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 message and exit the program. Here is the command you should run when executing your program:
lab
Where and 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 input file contains stock data pertaining to a customer. The first line of the input file indicates the name of the customer. The second line indicates their account number. The third line indicates the reporting date of the stock data for the customer. The remaining lines of the input file detail the name of the stock, number of shares held, highest and lowest price for the stock for the given day, and lastly the initial and closing price for the stock. Sample input file:
Customer Name Jolyne Cujoh
Account Number
Report Date
Stock Name TSLA
Shares Held
Opening Price
High Price
Low Price
Closing Price
Your program will read in each line using fgets then parse it using sscanf As noted by the man page of sscanf, the format string may contain directives such as a sequence of white space characters and ordinary non white space characters in addition to conversion specifiers. A white space character in the format string matches zero or more whitespace characters, and ordinary characters if present must match exactly to the string being parsed otherwise parsing stops.
For example, if we have the following code:
char buffer;
sscanfbillikakhana "billis buffer;
buffer will contain the string "kakhana".
But if we change the sscanf to the following:
sscanfbillikakhana "bilis buffer;
the sscanf call will fail to parse.
It may also be useful to look at assignment suppression characters and scansets in the man page of sscanf.
Each data header Customer Name, etc. will be delimited by a tab character followed by the mid character followed by another tab character.
Afterwards, you will write the output with the fields in a different order to the output file.
Calculations:
For the given customer data, you will determine the change in value of the shares held by the customer for the reported date.
Sample Output File
Customer: Jolyne Cujoh
Account:
Reporting Date:
beginarraylllltext Stock & text Open Price & text Close Price & text Loss text TSLA & & & endarray The first line indicates the customers name. The second line indicates the account number for the customer. The third line indicates the reporting date for the customer. The fourth line indicates the headings for what is reported on the fifth line. The fourth line indicates the Stock, Open Price, Close Price, and either Loss or Gain based off whether the change in value was positive or negative. Last, the fifth line indicates the stock name for the customer, the open price for the stock, the closing price for the stock, and the loss or gain reported.
"Stock" is left justified with a minimum width of
"Open Price" is left justified, min. width
"Close Price" is left justified, min. width
cdot "Loss" or "Gain" is left justified
Stock value is left justified, min width of
Open Price value is left justified, min. width with digits of precision
Close Price value is left justified, min. width with digits of precision
Loss or Gain value is left justified, with digits of precision
You must use the input file called input. txt provided with this assignment. Do not modify it in any way.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
