Hi, I was just wondering if anyone could help me fix the segmentation fraud in the programme below:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void Parse(string, string&, string&, string&, double&, int&);
void Display(string, string, string, double, int);
int main()
{
fstream InFile("WindStation00.data", ios::in);
string Line, ID, Date, Hour;
double Speed;
int Direction;
while(!InFile.eof()) {
InFile >> Line;
cout << "LINE: " << Line << endl;
Parse(Line, ID, Date, Hour, Speed, Direction);
Display(ID, Date, Hour, Speed, Direction);
}
InFile.close();
system("pause");
}
void Parse(string Line, string& ID, string& Date, string& Hour, double& Speed, int& Direction)
{
ID = strtok((char*)Line.c_str(), ":") ;
Date = strtok(0, ":");
Hour = strtok(0, ":");
Speed = atof(strtok(0, ":") ); //Converts a string of digits to a double...
Direction = atoi( strtok(0, ":") ); //Converts a string of digits to an int...
}
void Display(string ID, string Date, string Hour, double Speed, int Direction)
{
cout << "\tID = " << ID << endl;
cout << "\tDate = " << Date << endl;
cout << "\tHour = " << Hour << endl;
cout << "\tSpeed = " << Speed << endl;
cout << "\tDirection = " << Direction << endl;
}
I will greatly appreciate any suggestions. Thank You.