Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <string>
- #include <algorithm>
- #include <sstream>
- #include <memory>
- #include <vector>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- using namespace std;
- stringstream dane_do;
- string linia;
- int l = 1;
- int **Data;
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- fstream plik;
- plik.open("Dane.txt", ios::in );
- if(plik.good()==false)
- {
- ShowMessage("Bład otwarcia pliku");
- } ;
- fstream plik2;
- plik2.open("dane2.txt", ios::out | ios::app);
- while(getline(plik,linia)) {
- // wyciaganie pojedynczych danych z lini
- string rok = linia.substr(1,4);
- string miesiac = linia.substr(6,2);
- string dzien = linia.substr(9,2);
- string godzina = linia.substr(12,2);
- string minuta = linia.substr (15,2);
- string temp1 = linia.substr(21,5);
- string temp2 = linia.substr(30,5);
- string temp3 = linia.substr(39,5);
- string temp4 = linia.substr(48,5);
- string p = linia.substr(51,2);
- string em = linia.substr(62,3);
- string e1 = linia.substr(69,1);
- string e2 = linia.substr(74,1);
- string e3 = linia.substr(79,1);
- string e4 = linia.substr(84,1);
- //plik2<<rok<<" "<<miesiac<<" "<<dzien<<" "<<godzina<<" "<<
- //temp1<<" "<<temp2<<" "<<temp3<<" "<<temp4<<" "<<p<<" "<<
- //em<<" "<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<endl;
- //konwersja na inty
- int rokI = atoi(rok.c_str());
- int miesiacI = atoi(miesiac.c_str());
- int dzienI = atoi(dzien.c_str());
- int godzinaI = atoi(godzina.c_str());
- int minutaI = atoi(minuta.c_str());
- double temp1I = atof(temp1.c_str());
- double temp2I = atof(temp2.c_str());
- double temp3I = atof(temp3.c_str());
- double temp4I = atof(temp4.c_str());
- int pI = atoi(p.c_str());
- int emI = atoi(em.c_str());
- int e1I = atoi(e1.c_str());
- int e2I = atoi(e2.c_str());
- int e3I = atoi(e3.c_str());
- int e4I = atoi(e4.c_str());
- //ladowanie danych do tablicy data
- Data=(int**)malloc(l*sizeof(int *)); //alokacja pamieci
- for(int i=0; i<l; i++)
- {
- Data[i]=(int*)malloc(5*sizeof(int));
- for(int j = 0; j < 5; ++j)//wpisanie wartosci do tablicy
- {
- switch(j)
- {
- case 0:
- Data[i][j]=rokI;
- break;
- case 1:
- Data[i][j]=miesiacI;
- break;
- case 2:
- Data[i][j]=dzienI;
- break;
- case 3:
- Data[i][j]=godzinaI;
- break;
- case 4:
- Data[i][j]=minutaI;
- break;
- }
- }
- l++ ;
- }
- }
- plik2.close();
- plik.close();
- //dane[1][14] = {{atoi(rok.c_str()), miesiac, dzien, godz, temp1, temp2, temp3, temp4, p, em, e1, e2, e3, e4}};
- }
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- //ShowMessage(dane[0][3]);
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement