There are three small sub-activities and you are given three partially completed programs. Read the following instructions carefully and write your logic at TODO: line
There are three small sub-activities and you are given three partially completed programs. Read the following instructions carefully and write your logic at "TODO:" line of each program.
For this sub-activity, you need to write the contents of input file into an output file. Your program should generate an output file "stateDataOutput1.txt". You need to read the input file "stateData.txt", line by line, and each line should be written into the output file. You are required to add the logic in the partially completed program "stateData2.c".
>>stateDataOutput1.txt<<
Alabama , 4779736
Alaska , 710231
Arizona , 6392017
Arkansas , 2915918
California , 37253956
Colorado , 5029196
Connecticut , 3574097
Delaware , 897934
Florida , 18801310
Georgia , 9687653
Hawaii , 1360301
Idaho , 1567582
Illinois , 12830632
Indiana , 6483802
Iowa , 3046355
Kansas , 2853118
Kentucky , 4339367
Louisiana , 4533372
Maine , 1328361
Maryland , 5773552
Massachusetts , 6547629
Michigan , 9883640
Minnesota , 5303925
Mississippi , 2967297
Missouri , 5988927
Montana , 989415
Nebraska , 1826341
Nevada , 2700551
New Hampshire , 1316470
New Jersey , 8791894
New Mexico , 2059179
New York , 19378102
North Carolina , 9535483
North Dakota , 672591
Ohio , 11536504
Oklahoma , 3751351
Oregon , 3831074
Pennsylvania , 12702379
Rhode Island , 1052567
South Carolina , 4625364
South Dakota , 814180
Tennessee , 6346105
Texas , 25145561
Utah , 2763885
Vermont , 625741
Virginia , 8001024
Washington , 6724540
West Virginia , 1852994
Wisconsin , 5686986
Wyoming , 563626
>>"stateData2.c"<<
#include
#include
#include
int main(void) {
int const size = 200;
int const numStates = 50;
char tempBuffer[size];
char tmp[size];
char fileName[] = "stateData.txt"; // Name of the text file (input file) which contains states and its populations
char outFile[] = "stateDataOutput1.txt"; // Output file name
// Open the input file, quit if it fails...
FILE *instream = fopen(fileName, "r");
if(instream == NULL) {
fprintf(stderr, "Unable to open file: %s ", fileName);
exit(1);
}
//TODO: Open the output file in write ("w") mode
//TODO: Read the file, line by line and write each line into the output file
// Close the input file
fclose(instream);
//TODO: Close the output file
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started