Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //#define _XOPEN_SOURCE
  2.  
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <sys/types.h>
  9. #include <sys/wait.h>
  10.  
  11. struct msgBuf
  12. {
  13. int mtype;
  14. time_t time_0;
  15. };
  16.  
  17. int main()
  18. {
  19. char buffer[64];
  20. int pdesk[2];
  21. struct tm tm_1;
  22. struct tm tm_2;
  23. time_t time_1;
  24. time_t time_2;
  25.  
  26. struct msgBuf message;
  27.  
  28. switch(fork())
  29. {
  30. case -1:
  31. exit(1);
  32. case 0:
  33. pipe(pdesk);
  34.  
  35. switch(fork())
  36. {
  37. case -1:
  38. exit(1);
  39. case 0:
  40. printf("Podaj date w formacie DD.MM.YYYY/HH:MM:SS\n");
  41. scanf("%s", buffer);
  42.  
  43. strptime(buffer, "%d.%m.%Y/%H:%M:%S", &tm_1); //strptime konwertuje stringi czasu na strukture czasu
  44. time_1 = mktime(&tm_1); //funkcja konwertuje strukture tm na time_t
  45. write(pdesk[1], (char*)&time_1, sizeof(time_1)); //system call wypisuje dane z buffora
  46. break;
  47. default:
  48. while(!read(pdesk[0], (char*)&time_2, sizeof(time_2)))sleep(1);
  49. gmtime_r(&time_2, &tm_2); //transformuje dane i czas na broken-down time albo ASCII
  50. ++tm_2.tm_hour;
  51. strftime(buffer, sizeof(buffer), "%A %d.%m.%G/%H:%M:%S", &tm_2); //funkcja przeksztalca dane o czasie zawarte w strukturze tm na tekst
  52. //ktory umieszcza w tablicy s o ile ma on mniej niz max znakow
  53. printf("Data z dniem tygodnia: %s\n", buffer);
  54. break;
  55. }
  56. break;
  57.  
  58. default:
  59. wait(NULL);
  60. printf("KONIEC\n");
  61. break;
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement