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

Write a program that uses C style string functions to create data files usable a

ID: 3874311 • Letter: W

Question

Write a program that uses C style string functions to create data files usable as the input files for the Airline assignment 

You will be provided with a sample input file called inputdata.txt. It will contain sample data that could be used for the Airline assignment
o
This file will contain input strings in a comma separated value format. Each input line will contain, in order and separated by commas:
1.City name
2.Flying time
3.Layover time
o
Both the flying time and layover time will be formatted with an hours portion, a colon, and two digits representing the minutes. For a valid time, the minutes portion will be two digits and the hours portion will be either one or two digits (which might be 0).
You must create two output files. theTimes.dat will be a binary file containing the flying and layover times. theCities.txt will be a text file containing the city names. Both files must be created to conform to the requirements of the Airline assignment.

After opening the input file as a text file, loop, reading each line in the file one at a time. 
o
For each line
1.separate the input line into its component parts as described below.
2.output the city name to the text city name file.
3.output the times to the binary time file.
o
There could be any number of input lines.

After the loop is finished, close the files

Do error checking on all file I/O function calls, with appropriate error messages.

Do not get user input from the keyboard in 
your program. At all. I'm serious.

Assume a maximum string length of 80 characters (so your array must be 81 bytes long).

Quit the program 
without processing further input
upon an error occurring.

All error messages must have appropriate wording and correct spelling and grammar. 

Do not use 
strtok(), 
global va
riables, 
goto
, or exit()
.
Using any of these will result in a 
mark of 0.

Appropriate programming style as 
required in the course
must be used
.
Function Creation
Requirements

Function name: parseLine
o
Description: Separates a string into 
its
component parts, as described by the 
parameters.
The 
component parts are used to fill a struct that is pointed to by the 
second parameter.
o
Parameters:

char inputline[]: input line containing city
name and time information 
(originating from the input file)

struct CityInfo *pCityInfo: pointer to a struct that is filled in with the 
cityname and time information from the input line
o
Returns: 1 if OK, 0 if 
there are problems with the data

Function name: parseTime
o
Description: Separates a time string into hours and minutes
o
Parameters: 

char inputTime[]: string containing a time in the format hhh:mm (where 
there are one to three digits in the hour portion but 
exactly two digits in 
the minutes portion)

char *pHours: pointer to hours portion of the time

char *pMinutes: pointer to minutes portion of the time
o
Returns: 1 if OK, 0 if there are problems with the data

For both of the above functions, 
the expectation is
that you will check for the following 
possible problems with the data (as appropriate):
1.minutes exceeding 59
2.missing commas separating the components of the input line
3.missing colons separating the hours from the minutes of the time

although there are many other possible problems that could happen in the real world, no other problems with the data need to be accounted for
Design Requirements
You must use parseLine to separate the components of the input line.
Call it from main().

You must call parseTime from within parseLine to separate the components of the two 
times.

You must use C style strings, not C++. 

You will find that string related C library functions (such as those mentioned in lecture) will be your friends However, you must not use the strtok() function or any other third party or compiler provided tokenizing function (i.e. you need to do the separation of the components yourself).

Do not display any error messages in parseLine or parseTime. Any error messages 
should be displayed only in main()

inputData.txt Data File
Toronto,4:15,0:55
Atlanta,5:33,10:44
Kansas City,6:00,11:22
Anchorage,12:22,0:00

Explanation / Answer

As per your requirement the below one is solution please follow it

This program creates three file pointers pointing to an input file and two output files. The input file is opened and its conents are read iteratively into a string.

It also had a function to split a string into array of words. The first word is stored into the theCities output file and the second and third words are stored in theTimes output file.

C Program to read content of input file and store into the output files.

=========================================================

#include <stdio.h>

#include <stdlib.h>

void main()

{

FILE *inputfp,*theTimesfp,*theCitiesfp;

char str[80];

char arr[10][20];

if ((inputfp= fopen("inputdata.txt", "r")) == NULL) {

printf("cannot open file");

exit(1);

}

theTimesfp = fopen("theTimes.dat", "w");

theCitiesfp = fopen("theCities.txt", "w");

while(!feof(inputfp)) {

fgets(str,79,inputfp);

printf("%s",str);

/* gets the words into array seperated by comma.*/

n=getWords(str,arr);

for(i=0;i<=n;i++){

fprintf(theCitiesfp,"%s ", arr[0]);

fprintf(theTimesfp,"%s,%s ",arr[1],arr[2]);

}

}

fclose(inputfp);

fclose(theTimesfp);

fclose(theCitiesfp);

}

int getWords(char *base, char target[10][20])

{

int n=0,i,j=0;

for(i=0;TRUE;i++)

{

if(base[i]!=','){

target[n][j++]=base[i];

}

else{

target[n][j++]='';//insert NULL

n++;

j=0;

}

if(base[i]=='')

break;

}

return n;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote