Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SO IS1 222B LAB07
- //Grzegorz Muth
- //mg44436@zut.edu.pl
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <time.h>
- void str_copy(char *to, const char *from)
- {
- while(*to++ = *from++);
- }
- int str_len(char *s)
- {
- int i = 0;
- while(*s++ != '\0')
- i++;
- return i;
- }
- void str_cut(char *s, size_t n)
- {
- int i;
- for(i = 0; i < n; i++)
- *s++;
- *s = '\0';
- }
- void int_to_char(int n, char s)
- {
- s = n + 48;
- return s;
- }
- struct log {
- struct tm date; // czas
- char argument[10]; // napisz argumentu wywołania
- };
- int main(int argc, char *argv[]){
- if(argc == 1)
- exit(1);
- int opt;
- struct log obiekcik;
- time_t ptr;
- time(&ptr);
- char* rezultat;
- int handle;
- while((opt = getopt(argc, argv, "rw:")) != -1)
- {
- switch(opt)
- {
- case 'w':
- localtime_r(&ptr, &obiekcik.date);
- printf("%d\n", obiekcik.date.tm_mon + 1);
- str_cut(argv[2], 9);
- str_copy(obiekcik.argument, argv[2]);
- printf("%s\n", obiekcik.argument);
- char name[21];
- char a[5];
- //sprintf(obiekcik.date.tm_year + 1900, a, 10);
- //str_copy(name, a);
- int_to_char(obiekcik.date.tm_year + 1900, a);
- printf("%s\n", a);
- //str_copy(name, ".");
- /*str_copy(name[5], itoa(obiekcik.date.tm_mon + 1));
- str_copy(name[7], ".");
- str_copy(name[, itoa(obiekcik.date.tm_mday));
- str_copy(name[, ".");
- str_copy(name, itoa(obiekcik.date.tm_hour));
- str_copy(name, ".");
- str_copy(name, itoa(obiekcik.date.tm_min));
- str_copy(name, ".");
- str_copy(name, "log");*/
- //printf("%s\n", name);
- /*handle = open("msg.txt", O_RDWR | O_CREAT, S_IRWXU);
- if(handle >= 0)
- {
- read(0, &input, 1);
- write(handle, &input, sizeof(input));
- }
- close(handle);*/
- break;
- case 'r':
- break;
- default:
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement