Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Abstract This assignment is based on a class of problem solved in enterprise com

ID: 3849418 • Letter: A

Question

Abstract This assignment is based on a class of problem solved in enterprise computing: extraction, transfor- mation, and loading. This is often referred to as ETL. The inputs will be data extracted from a leading aviation industry data and consulting firm, GCR. (See GCR.com for additional data.) The data is in a well known format where each data element is separated from the previous and following data elements by using a comma. It should be noted that this method of data manipulation is extremely common. The explicit order of the data fields and the desired outputs are defined in the "Specifications". objectives 1 The objectives of this assignment are to demonstrate proficiency in file lo, data structures, and data trans- formation using C language resources. Specifically, you will read in data from a text file, use that data to populate a data structure, and print that data to STDOUT by accessing the newly populated structure. 1.1 Extraction The first part of ETL is extraction. The filename of a text file will be passed to your program via the com- mand line. The data contained in that file is to be read into memory (i.e.. extracted). Your program will be compiled and run on Eustis using the following commands: gcc o etl hwletl.c /etl input File It is entirely possible that the input file either does not exist or is not where it is supposed to be. In such an event, your program should print an error message to STDERR that indicates which file is missing, then your program should exit safely. Use the following format for your error message (fileName should display the actual name of the missing file): etl ERROR: File fileName not found

Explanation / Answer

Here is the code for the question. Tested with sample data with 2 lines. You need to pass the file name as command line argument to run the program.In case you have any issues running on your test files , please post a comment and I shall respond to it. Please don't forget to rate the answer if it helped. Thank you very much.

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "airPdata.h"

#define MAX_RECORDS 1000

#define BUFFER_SIZE 500

int LoadFile(FILE *fptr, airPdata* airport[] );

void PrintData(airPdata *airport);

int main(int argc, char** argv)

{

FILE *fptr;

airPdata* airports[MAX_RECORDS];

int count = 0;

  

if(argc != 2)

{

fprintf(stderr, "ERROR: need input filename as command line argument " );

exit(1);

}

  

fptr = fopen(argv[1], "r");

if(!fptr)

{

fprintf(stderr, "ERROR: File %s not found.", argv[1]);

exit(1);

}

  

count = LoadFile(fptr, airports);

fclose(fptr);

  

//print report

  

//print header

printf("%-12s %-11s %-42s %-34s %-3s %-15s %-16s Tower ",

   "FAA Site", "Short Name", "Airport Name", "City", "ST", "Latitude", "Longitude");

printf("%-12s %-11s %-42s %-34s %-3s %-15s %-16s ===== ",

   "========", "==========", "============", "====", "==", "========", "=========");

  

for(int i = 0; i < count; i++)

PrintData(airports[i]);

  

}

int LoadFile(FILE *fptr, airPdata* airport[] )

{

char buffer[BUFFER_SIZE];

char separator[2]=",";

char *token;

int count = 0;

while(fgets(buffer, BUFFER_SIZE, fptr)) //read a line into buffer

{

airport[count] = malloc(sizeof(airPdata));

  

   //break into tokens based on comma separator

//1st token site number

token = strtok(buffer, separator);

airport[count]->siteNumber = malloc(strlen(token));

strcpy(airport[count]->siteNumber, token);

  

//next token loc id

token = strtok(NULL, separator);

airport[count]->LocID = malloc(strlen(token));

strcpy(airport[count]->LocID, token);

  

//next token fieldname

token = strtok(NULL, separator);

airport[count]->fieldName = malloc(strlen(token));

strcpy(airport[count]->fieldName, token);

  

//next token city

token = strtok(NULL, separator);

airport[count]->city = malloc(strlen(token));

strcpy(airport[count]->city, token);

  

//next token state

token = strtok(NULL, separator);

airport[count]->state = malloc(strlen(token));

strcpy(airport[count]->state, token);

  

//next token latitude

token = strtok(NULL, separator);

airport[count]->latitude = malloc(strlen(token));

strcpy(airport[count]->latitude, token);

  

//next token longitude

token = strtok(NULL, separator);

airport[count]->longitude = malloc(strlen(token));

strcpy(airport[count]->longitude, token);

  

//next token tower

token = strtok(NULL, separator);

airport[count]->controlTower = token[0]; // single character

  

count++;

}

  

return count;

}

void PrintData(airPdata *airport)

{

if(airport == NULL)

{

fprintf(stderr,"ERROR: received null for airport in PrintData");

return;

}

printf("%-12s %-11s %-42s %-34s %-3s %-15s %-16s %c ",

   airport->siteNumber, airport->LocID, airport->fieldName, airport->city, airport->state, airport->latitude, airport->longitude, airport->controlTower );

}

input file airport.txt

0000.35*H,2FD7,AIR ORLANDO,ORLANDO,FL,28-26-08.0210N,081-28-23.2590W,Y
OOOO.1*H,3FD5,ARNOLD PALMER HOSPITAL,ORLANDO,FL,28-31021.0090N,081-22-49.2520W,N

output

FAA Site Short Name Airport Name City ST Latitude Longitude Tower
======== ========== ============ ==== == ======== ========= =====
0000.35*H 2FD7 AIR ORLANDO ORLANDO FL 28-26-08.0210N 081-28-23.2590W Y
OOOO.1*H 3FD5 ARNOLD PALMER HOSPITAL ORLANDO FL 28-31021.0090N 081-22-49.2520W N