Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <iostream>
- using namespace std;
- struct pomiar {
- unsigned int nr_pomiaru;
- unsigned int nr_czujnika;
- char data_i_czas[20];
- double temp;
- struct pomiar* nast = NULL;
- };
- // policz linie w pliku
- int lines(FILE* f) {
- char buffer[100];
- int count = 0;
- while (!feof(f)) {
- fscanf(f, "%s", buffer);
- count += 1;
- }
- rewind(f);
- return count / 4;
- }
- int main() {
- // deklaracje
- struct pomiar* wsk = NULL;
- struct pomiar* poczatek = NULL;
- unsigned int nr_pomiaru;
- unsigned int nr_czujnika;
- char data_i_czas[20];
- double temp;
- int rok;
- FILE* stream;
- // sprawdzenie czy plik sie otworzy
- if ((stream = fopen("temp.txt", "r")) == NULL) {
- exit(1);
- }
- // pobranie danych, przypisanie ich do wskaznikow, zamkniecie pliku
- fscanf(stream, "%u %u %s %lf", &nr_pomiaru, &nr_czujnika, data_i_czas, &temp);
- for (!feof(stream);;) {
- if (poczatek == NULL) {
- poczatek = wsk = (pomiar*)malloc(sizeof(pomiar));
- }
- else {
- wsk->nast = (pomiar*)malloc(sizeof(pomiar));
- wsk = wsk->nast;
- }
- wsk->nr_pomiaru = nr_pomiaru;
- wsk->nr_czujnika = nr_czujnika;
- strcpy(wsk->data_i_czas, data_i_czas);
- wsk->temp = temp;
- wsk->nast = NULL;
- cout << wsk->nr_pomiaru << ' ' << wsk->nr_czujnika << ' ' << wsk->data_i_czas << ' ' << wsk->temp << endl;
- fscanf(stream, "%u %u %s %lf", &nr_pomiaru, &nr_czujnika, data_i_czas, &temp);
- }
- int l = lines(stream);
- fclose(stream);
- //struct pomiar* czujnik_1 = NULL;
- //int jeden = 0;
- //struct pomiar* czujnik_2 = NULL;
- //int dwa = 0;
- //struct pomiar* czujnik_3 = NULL;
- //int trzy = 0;
- //struct pomiar* czujnik_4 = NULL;
- //int cztery = 0;
- //int c = 0;
- //while (wsk) {
- // c++;
- // wsk = wsk->nast;
- //}
- //cout << "ilosc elementow listy: " << c << endl << endl;
- //for (int i = 0; i < l; i++) {
- // if (wsk[i].nr_czujnika = 1) {
- // czujnik_1->nr_czujnika = wsk[i].nr_czujnika;
- // jeden++;
- // }
- // else if (wsk[i].nr_czujnika = 2) {
- // czujnik_2->nr_czujnika = wsk[i].nr_czujnika;
- // dwa++;
- // }
- // else if (wsk[i].nr_czujnika = 3) {
- // czujnik_3->nr_czujnika = wsk[i].nr_czujnika;
- // trzy++;
- // }
- // else {
- // czujnik_4->nr_czujnika = wsk[i].nr_czujnika;
- // cztery++;
- // }
- //}
- //cout << "Ilosc pomiarow z pierwszego czujnika: " << jeden << endl;
- //cout << "Ilosc pomiarow z drugiego czujnika: " << dwa << endl;
- //cout << "Ilosc pomiarow z trzeciego czujnika: " << trzy << endl;
- //cout << "Ilosc pomiarow z czwartego czujnika: " << cztery << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement