Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.24 KB | None | 0 0
  1. //SO IS1 222B LAB07
  2. //Grzegorz Muth
  3. //mg44436@zut.edu.pl
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <sys/stat.h>
  8. #include <sys/types.h>
  9. #include <fcntl.h>
  10. #include <time.h>
  11.  
  12. void str_copy(char *to, const char *from)
  13. {
  14.     while(*to++ = *from++);
  15. }
  16.  
  17. int str_len(char *s)
  18. {
  19.     int i = 0;
  20.     while(*s++ != '\0')
  21.         i++;
  22.  
  23.     return i;
  24. }
  25.  
  26. void str_cut(char *s, size_t n)
  27. {
  28.     int i;
  29.  
  30.     for(i = 0; i < n; i++)
  31.         *s++;
  32.  
  33.     *s = '\0';
  34. }
  35.  
  36. void int_to_char(int n, char s)
  37. {
  38.     s = n + 48;
  39.     return s;
  40.  
  41. }
  42.  
  43. struct log {
  44.     struct tm date; // czas
  45.     char argument[10]; // napisz argumentu wywołania
  46. };
  47.  
  48. int main(int argc, char *argv[]){
  49.  
  50.     if(argc == 1)
  51.         exit(1);
  52.  
  53.     int opt;
  54.     struct log obiekcik;
  55.  
  56.     time_t ptr;
  57.     time(&ptr);
  58.     char* rezultat;
  59.  
  60.     int handle;
  61.  
  62.  
  63.  
  64.     while((opt = getopt(argc, argv, "rw:")) != -1)  
  65.     {  
  66.         switch(opt)  
  67.         {  
  68.             case 'w':
  69.  
  70.                 localtime_r(&ptr, &obiekcik.date);
  71.                 printf("%d\n", obiekcik.date.tm_mon + 1);
  72.                 str_cut(argv[2], 9);
  73.                 str_copy(obiekcik.argument, argv[2]);
  74.                 printf("%s\n", obiekcik.argument);
  75.                 char name[21];
  76.                 char a[5];
  77.  
  78.                 //sprintf(obiekcik.date.tm_year + 1900, a, 10);
  79.                 //str_copy(name, a);
  80.                 int_to_char(obiekcik.date.tm_year + 1900, a);
  81.                 printf("%s\n", a);
  82.                 //str_copy(name, ".");
  83.  
  84.  
  85.                 /*str_copy(name[5], itoa(obiekcik.date.tm_mon + 1));
  86.                 str_copy(name[7], ".");
  87.                 str_copy(name[, itoa(obiekcik.date.tm_mday));
  88.                 str_copy(name[, ".");
  89.                 str_copy(name, itoa(obiekcik.date.tm_hour));
  90.                 str_copy(name, ".");
  91.                 str_copy(name, itoa(obiekcik.date.tm_min));
  92.                 str_copy(name, ".");
  93.                 str_copy(name, "log");*/
  94.  
  95.                 //printf("%s\n", name);
  96.  
  97.                 /*handle = open("msg.txt", O_RDWR | O_CREAT, S_IRWXU);
  98.                 if(handle >= 0)
  99.                 {
  100.                     read(0, &input, 1);
  101.                     write(handle, &input, sizeof(input));
  102.                 }
  103.                 close(handle);*/
  104.  
  105.  
  106.                 break;
  107.             case 'r':
  108.                 break;
  109.             default:
  110.                 break;
  111.  
  112.            
  113.         }  
  114.     }  
  115.  
  116.    
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement