Need help with reading/converting text file

Hello, I'm having a lot of trouble with this program. I need to extract things from lines in file. for example one of the lines would be:
2013-05-07-1430, DTW, 150SW, FL330, Delta123
with this I would need to convert the first section to a date and time like "May 7, 2013" "2:30pm" then I would have to convert DTW to "Detroit Metro Airport", then convert 150SW to "150 miles southwest", then FL330 to "33,000 feet" and Delta123 to "Delta 123". I'm having problems extracting the portions of this file. I'm used to grabbing information within the commas but not within letters and numbers. I could use some help on how to do that. thank you


Write a C++ program to process air traffic control data stored in a comma-delimited file. The data relates to incidents of severe turbulence and you wish to create a plain text summary report for the file.

You will not know how many lines of data will be in the file. The format for the file will be:


{date},{airportcode},{distance from city},{flightlevel},{flightID}

An example data line for the file could be:


2013-05-07-1430,DTW,150SW,FL330,Delta123

The format for the date/time will always be exactly 15 characters (yyyy-mm-dd-hhmm).

CORRECTION:
The airport code will always be precisely three characters. The distance string will of course will vary,but the number will always be a one or two-digit integer followed by a two-character compass direction (N=north, NE-northeast, E=east, and so on). The altitude is presented as a coded number requiring the digits after the “FL” to be extracted. Add two zeroes to this value (along with a comma) to convert the flight altitude to feet.. Finally, the aircraft identifier will vary in the number of characters but will always be the last field in the line.

The provided file flights.txt will vary in the number of flight data lines. Be sure to use an end-of-file loop to drive the processing of your program. Each line of the input file includes one flight, time, and location. For each line of input, write an output message that can be printed:

Given the example above, the with output then:


Flight: Delta 123
Date: May 7, 2013
Time: 2:30 pm
Location: 150 miles southwest of Detroit Metropolitan Airport
Altitude: 33,000 feet

Your output should then be a list of these summaries, one for each observation. One additional data file will be required to allow you to convert the airport code to the airport name. Data file miairports.txt includes many actual airport identifiers and names. Your program will need to read this file into an array so that it can be searched as you process each line of the primary input file.


The program is presented in modular form using functions. You should continue this design with functions for the new features you are adding.



Here is the code description


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// This program processes air traffic control data stored in a comma-delimited file
// The data relates to incidents of severe turbulence 
// and displays a plain text summary report for the file.
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
// prototypes
void GetList(ifstream& InFile, int date[], int airportcode[], int distance[], int level[], int ID[], int& totalRecs);
int strIndex(char inStr[], int start, char searchTarget);
void substring(char inStr[], int start, int end, char outStr[]);

const int Max = 1000; // Max number of data lines


int main()
{
	// Array of list elements 
	char inputLine[60];
	int totalRecs = 0;
	char id[4];
	int date[Max];
	char dateString[16];
	int airportcode[Max];
	int distance[Max];
	int level[Max];
	char levelstring[6];
	char templevelstring[6];
	int ID[Max];
	int flight, date2, time, pmam, miles, direction, alt, pos, index, oldpos, Level, airport;
	ifstream InFile;
	InFile.open("flights.txt");


	// File initialization 
	ifstream inFile("flights.txt");
	if (inFile.fail())         // Test for file existence 
	{
		cout << "Problem opening file";
		exit(-1);
	}

	// Read file and count balues in array
	GetList(InFile, date, airportcode, distance, level, ID, totalRecs);

	while (!InFile.eof())
	{
		// locate date substring
		pos = strIndex(inputLine, 0, ',');
		substring(inputLine, 0, pos - 1, dateString);
		date2 = atoi(dateString);
		// locate airport code and convert
		pos = strlen(inputLine)- 1;
		substring(inputLine, oldpos + 1, pos, id);
		// locate distance from city and extract "SW" then conver

		// locate flight level and extract "FL"
		oldpos = pos;
		pos = strIndex(inputLine, oldpos + 1, ',');
		substring(inputLine, oldpos + 1, pos - 1, levelstring);
		oldpos = pos;
		pos = strIndex(levelstring, 0, ',');
		substring(levelstring, 0, pos-1, templevelstring);
		strcpy(levelstring, templevelstring);
		Level = atof(levelstring);
		// locate flight ID and convert 


	}



	// Output message
	cout << "Flight: " << flight << endl;
	cout << "Date: " << date2 << endl;
	cout << "Time: " << time << " " << pmam << endl;
	cout << "Location: " << miles <<" miles " << direction << " of " << airport << endl;
	cout << "Altitude: " << alt << " feet" << endl;

	system("pause");
	return 0;
}

void GetList(ifstream& InFile, int date[], int airportcode[], int distance[], int level[], int ID[], int& totalRecs)
{

	int i = 0;

	// Priming read 

	InFile >> date[i] >> airportcode[i] >> distance[i] >> level[i] >> ID[i];

	while (!InFile.eof())
	{
		i++; // Add one to pointer
		// continuation reads
		InFile >> date[i] >> airportcode[i] >> distance[i] >> level[i] >> ID[i];
	}

	totalRecs = i;

}
void substring(char inStr[], int start, int end, char outStr[])
{
	strcpy(outStr, "");             // Empty output string 

	int pos = 0;                    // To mark curr position of substring 
	for (int i = start; i <= end; i++)
	{
		outStr[pos] = inStr[i];      // Move character to output string 
		pos++;                       // Manually advance position marker 
	}

	outStr[pos] = '\0';             // Add null character to complete string 
}
int strIndex(char inStr[], int start, char searchTarget)
{
	int pos = start;       // Set position marker to start index 
	int returnPos = -1;    // Character position marker, assume not found 
	bool found = false;    // Assume not found at start 

	while (inStr[pos] != '\0' && !found)
	{
		if (inStr[pos] == searchTarget)   // If character found, 
		{
			returnPos = pos;               // Mark position 
			found = true;                  // Ready for exit from loop 
		}
		else
			pos++;                         // Otherwise, move to next character 

	}
	return returnPos;                    // Return value 
}
// This function puts the flight ID into a different format
void FlightID()
{

}
// This function converts the date into a different form and displays it
void DateChg()
{

}
// This fucktion takes the data from the date and converts it to time
// Displays it
void Time()
{

}
// This function takes the distance and airport code
// Changes it to the airport name and distance in miles
// Displays it in the proper format
void Location()
{

}
// This function takes the fightlevel and converts it to feet
// Then displays it
void Altitude()
{

}
**
Topic archived. No new replies allowed.