Advertisement
Guest User

Kod Program

a guest
Jan 18th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <windows.h>
  9. #include <string>
  10. #include <algorithm>
  11. #include <sstream>
  12. #include <memory>
  13. #include <vector>
  14. #pragma hdrstop
  15.  
  16. #include "Unit1.h"
  17. //---------------------------------------------------------------------------
  18. #pragma package(smart_init)
  19. #pragma resource "*.dfm"
  20. using namespace std;
  21.  
  22.  
  23.  
  24. stringstream dane_do;
  25. string linia;
  26.  
  27.  
  28. int l = 1;
  29.  
  30. int **Data;
  31.  
  32.  
  33. TForm1 *Form1;
  34. //---------------------------------------------------------------------------
  35. __fastcall TForm1::TForm1(TComponent* Owner)
  36. : TForm(Owner)
  37. {
  38. }
  39. //---------------------------------------------------------------------------
  40.  
  41.  
  42. void __fastcall TForm1::Button1Click(TObject *Sender)
  43. {
  44. fstream plik;
  45. plik.open("Dane.txt", ios::in );
  46.  
  47. if(plik.good()==false)
  48. {
  49. ShowMessage("Bład otwarcia pliku");
  50. } ;
  51.  
  52. fstream plik2;
  53. plik2.open("dane2.txt", ios::out | ios::app);
  54.  
  55. while(getline(plik,linia)) {
  56.  
  57. // wyciaganie pojedynczych danych z lini
  58. string rok = linia.substr(1,4);
  59. string miesiac = linia.substr(6,2);
  60. string dzien = linia.substr(9,2);
  61. string godzina = linia.substr(12,2);
  62. string minuta = linia.substr (15,2);
  63. string temp1 = linia.substr(21,5);
  64. string temp2 = linia.substr(30,5);
  65. string temp3 = linia.substr(39,5);
  66. string temp4 = linia.substr(48,5);
  67. string p = linia.substr(51,2);
  68. string em = linia.substr(62,3);
  69. string e1 = linia.substr(69,1);
  70. string e2 = linia.substr(74,1);
  71. string e3 = linia.substr(79,1);
  72. string e4 = linia.substr(84,1);
  73.  
  74. //plik2<<rok<<" "<<miesiac<<" "<<dzien<<" "<<godzina<<" "<<
  75. //temp1<<" "<<temp2<<" "<<temp3<<" "<<temp4<<" "<<p<<" "<<
  76. //em<<" "<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<endl;
  77. //konwersja na inty
  78.  
  79. int rokI = atoi(rok.c_str());
  80. int miesiacI = atoi(miesiac.c_str());
  81. int dzienI = atoi(dzien.c_str());
  82. int godzinaI = atoi(godzina.c_str());
  83. int minutaI = atoi(minuta.c_str());
  84. double temp1I = atof(temp1.c_str());
  85. double temp2I = atof(temp2.c_str());
  86. double temp3I = atof(temp3.c_str());
  87. double temp4I = atof(temp4.c_str());
  88. int pI = atoi(p.c_str());
  89. int emI = atoi(em.c_str());
  90. int e1I = atoi(e1.c_str());
  91. int e2I = atoi(e2.c_str());
  92. int e3I = atoi(e3.c_str());
  93. int e4I = atoi(e4.c_str());
  94.  
  95.  
  96. //ladowanie danych do tablicy data
  97. Data=(int**)malloc(l*sizeof(int *)); //alokacja pamieci
  98. for(int i=0; i<l; i++)
  99. {
  100. Data[i]=(int*)malloc(5*sizeof(int));
  101. for(int j = 0; j < 5; ++j)//wpisanie wartosci do tablicy
  102. {
  103. switch(j)
  104. {
  105. case 0:
  106. Data[i][j]=rokI;
  107. break;
  108. case 1:
  109. Data[i][j]=miesiacI;
  110. break;
  111. case 2:
  112. Data[i][j]=dzienI;
  113. break;
  114. case 3:
  115. Data[i][j]=godzinaI;
  116. break;
  117. case 4:
  118. Data[i][j]=minutaI;
  119. break;
  120. }
  121. }
  122. l++ ;
  123.  
  124. }
  125. }
  126.  
  127. plik2.close();
  128. plik.close();
  129.  
  130. //dane[1][14] = {{atoi(rok.c_str()), miesiac, dzien, godz, temp1, temp2, temp3, temp4, p, em, e1, e2, e3, e4}};
  131.  
  132.  
  133.  
  134. }
  135. void __fastcall TForm1::Button2Click(TObject *Sender)
  136. {
  137. //ShowMessage(dane[0][3]);
  138. }
  139. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement