Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "stdio.h"
- #include "stdlib.h"
- using namespace std;
- struct Time
- {
- int hTens, hOnes, mTens, mOnes;
- void printTime()
- {
- cout<<hTens<<hOnes<<':'<<mTens<<mOnes<<endl;
- }
- };
- struct FlightTimes
- {
- Time flyOutTime,flyInTime;
- };
- struct Flight
- {
- //FlightTimes times;
- int from, to;
- FlightTimes * flightArr1;
- int flightCount;
- void makeFlightArr()
- {
- cout<<"Makes array with "<<flightCount<<endl;
- flightArr1 = new FlightTimes[flightCount]; // Man vajag šajā masīvā ielikt to temp
- cout<<sizeof(flightArr1)<<endl;//Man viņš ir ar tipu FlightTimes. Tāds pats kāds temp
- }
- };
- struct FlightCalculator
- {
- Time startTime;
- int flightAmount, startAirport, endAirport, notLast;
- char str[100];
- FlightTimes *FlightTimes, temp;//<---- temp
- char trash1,trash2,trash3;
- Flight * flightArr;
- int flightNo = 0;
- void letsGo()
- {
- FILE * nice;
- nice = fopen("lidosta.in", "r");
- getMainInfo(nice);
- while(true)
- {
- Flight * current = new Flight(); // Nodefinējas current
- if(fgets(str, 100, nice)==NULL) break;
- sscanf(str,"%u",¬Last);
- if(!notLast) break;
- char restOfTimes[100] = {NULL};
- sscanf(str,"%u %u %u %[^\t\n]",¤t->from,¤t->to,¤t->flightCount,restOfTimes);
- cout<<current->flightCount<<endl;
- current->makeFlightArr();
- int i = current->flightCount;
- while(i)
- {
- restOfTimes[0]==NULL;
- //break;
- // sscanf(str,"%u %u %u %[^\t\n]",¤t->from,¤t->to,¤t->flightCount,restOfTimes);
- sscanf(restOfTimes,"%1u %1u %1c %1u %1u %1c %1u %1u %1c %1u %1u %[^\t\n] ",
- &temp.flyOutTime.hTens,
- &temp.flyOutTime.hOnes,
- &trash1,
- &temp.flyOutTime.mTens,
- &temp.flyOutTime.mOnes,
- &trash2,
- &temp.flyInTime.hTens,
- &temp.flyInTime.hOnes,
- &trash3,
- &temp.flyInTime.mTens,
- &temp.flyInTime.mOnes,
- &restOfTimes);
- cout<<temp.flyOutTime.hTens<<temp.flyOutTime.hOnes<<':'<<temp.flyOutTime.mTens<<temp.flyOutTime.mOnes<<endl;
- //cout<<restOfTimes<<endl;
- current->flightArr1[i] = temp; // Te notiek crash
- cout<<sizeof(current->flightArr1)<<endl;//[i] = temp;
- //temp.flyInTime.printTime();
- // temp.flyOutTime.printTime();
- i--;
- // if(i==3)
- // break;
- }
- cout<<endl;
- //cout<<strlen(str)<<endl;
- if(restOfTimes[0]!=NULL)
- {
- //cout<<restOfTimes<<" test"<<endl;
- }
- }
- fclose(nice);
- }
- void makeFlightArr(int i)
- {
- flightArr = new Flight[i];
- }
- void getMainInfo(FILE * nice)
- {
- fgets(str, 100, nice);
- sscanf(str,"%1u",&flightAmount);
- makeFlightArr(flightAmount);
- cout<<flightAmount<<endl;
- fgets(str, 100, nice);
- sscanf(str,"%1u %1u",&startAirport, &endAirport);
- cout<<startAirport<<' '<<endAirport<<endl;
- fgets(str, 100, nice);
- sscanf(str,"%1u %1u %1c %1u %1u",&startTime.hTens,&startTime.hOnes,&trash1,&startTime.mTens, &startTime.mOnes);
- startTime.printTime();
- }
- };
- int main()
- {
- FlightCalculator flight;
- flight.letsGo();
- //cout<<"Hello world";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement