Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. struct pomiar {
  9. unsigned int nr_pomiaru;
  10. unsigned int nr_czujnika;
  11. char data_i_czas[20];
  12. double temp;
  13. struct pomiar* nast = NULL;
  14. };
  15.  
  16. // policz linie w pliku
  17. int lines(FILE* f) {
  18. char buffer[100];
  19. int count = 0;
  20. while (!feof(f)) {
  21. fscanf(f, "%s", buffer);
  22. count += 1;
  23. }
  24. rewind(f);
  25. return count / 4;
  26. }
  27.  
  28. int main() {
  29.  
  30. // deklaracje
  31. struct pomiar* wsk = NULL;
  32. struct pomiar* poczatek = NULL;
  33. unsigned int nr_pomiaru;
  34. unsigned int nr_czujnika;
  35. char data_i_czas[20];
  36. double temp;
  37. int rok;
  38. FILE* stream;
  39.  
  40. // sprawdzenie czy plik sie otworzy
  41. if ((stream = fopen("temp.txt", "r")) == NULL) {
  42. exit(1);
  43. }
  44.  
  45. // pobranie danych, przypisanie ich do wskaznikow, zamkniecie pliku
  46. fscanf(stream, "%u %u %s %lf", &nr_pomiaru, &nr_czujnika, data_i_czas, &temp);
  47. for (!feof(stream);;) {
  48. if (poczatek == NULL) {
  49. poczatek = wsk = (pomiar*)malloc(sizeof(pomiar));
  50. }
  51. else {
  52. wsk->nast = (pomiar*)malloc(sizeof(pomiar));
  53. wsk = wsk->nast;
  54. }
  55. wsk->nr_pomiaru = nr_pomiaru;
  56. wsk->nr_czujnika = nr_czujnika;
  57. strcpy(wsk->data_i_czas, data_i_czas);
  58. wsk->temp = temp;
  59. wsk->nast = NULL;
  60. cout << wsk->nr_pomiaru << ' ' << wsk->nr_czujnika << ' ' << wsk->data_i_czas << ' ' << wsk->temp << endl;
  61.  
  62. fscanf(stream, "%u %u %s %lf", &nr_pomiaru, &nr_czujnika, data_i_czas, &temp);
  63. }
  64. int l = lines(stream);
  65. fclose(stream);
  66.  
  67. //struct pomiar* czujnik_1 = NULL;
  68. //int jeden = 0;
  69. //struct pomiar* czujnik_2 = NULL;
  70. //int dwa = 0;
  71. //struct pomiar* czujnik_3 = NULL;
  72. //int trzy = 0;
  73. //struct pomiar* czujnik_4 = NULL;
  74. //int cztery = 0;
  75.  
  76. //int c = 0;
  77. //while (wsk) {
  78. // c++;
  79. // wsk = wsk->nast;
  80. //}
  81. //cout << "ilosc elementow listy: " << c << endl << endl;
  82.  
  83. //for (int i = 0; i < l; i++) {
  84. // if (wsk[i].nr_czujnika = 1) {
  85. // czujnik_1->nr_czujnika = wsk[i].nr_czujnika;
  86. // jeden++;
  87. // }
  88. // else if (wsk[i].nr_czujnika = 2) {
  89. // czujnik_2->nr_czujnika = wsk[i].nr_czujnika;
  90. // dwa++;
  91. // }
  92. // else if (wsk[i].nr_czujnika = 3) {
  93. // czujnik_3->nr_czujnika = wsk[i].nr_czujnika;
  94. // trzy++;
  95. // }
  96. // else {
  97. // czujnik_4->nr_czujnika = wsk[i].nr_czujnika;
  98. // cztery++;
  99. // }
  100. //}
  101.  
  102. //cout << "Ilosc pomiarow z pierwszego czujnika: " << jeden << endl;
  103. //cout << "Ilosc pomiarow z drugiego czujnika: " << dwa << endl;
  104. //cout << "Ilosc pomiarow z trzeciego czujnika: " << trzy << endl;
  105. //cout << "Ilosc pomiarow z czwartego czujnika: " << cztery << endl;
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement