Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define _XOPEN_SOURCE
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- struct msgBuf
- {
- int mtype;
- time_t time_0;
- };
- int main()
- {
- char buffer[64];
- int pdesk[2];
- struct tm tm_1;
- struct tm tm_2;
- time_t time_1;
- time_t time_2;
- struct msgBuf message;
- switch(fork())
- {
- case -1:
- exit(1);
- case 0:
- pipe(pdesk);
- switch(fork())
- {
- case -1:
- exit(1);
- case 0:
- printf("Podaj date w formacie DD.MM.YYYY/HH:MM:SS\n");
- scanf("%s", buffer);
- strptime(buffer, "%d.%m.%Y/%H:%M:%S", &tm_1); //strptime konwertuje stringi czasu na strukture czasu
- time_1 = mktime(&tm_1); //funkcja konwertuje strukture tm na time_t
- write(pdesk[1], (char*)&time_1, sizeof(time_1)); //system call wypisuje dane z buffora
- break;
- default:
- while(!read(pdesk[0], (char*)&time_2, sizeof(time_2)))sleep(1);
- gmtime_r(&time_2, &tm_2); //transformuje dane i czas na broken-down time albo ASCII
- ++tm_2.tm_hour;
- strftime(buffer, sizeof(buffer), "%A %d.%m.%G/%H:%M:%S", &tm_2); //funkcja przeksztalca dane o czasie zawarte w strukturze tm na tekst
- //ktory umieszcza w tablicy s o ile ma on mniej niz max znakow
- printf("Data z dniem tygodnia: %s\n", buffer);
- break;
- }
- break;
- default:
- wait(NULL);
- printf("KONIEC\n");
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement