Advertisement
Tavi33

lab4 so

Oct 17th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8.  
  9. int main(int argc, char *argv[]){
  10.   if(argc != 3)
  11.     printf("Usage file dir");
  12.   int a;
  13.   int b;
  14.   char buff[20];
  15.  
  16.   a = open(argv[1], O_RDONLY, S_IWUSR | S_IRUSR);
  17.  
  18.   size_t nbytes;
  19.   nbytes = sizeof(buff);
  20.   if(read(a, buff, nbytes) == -1)
  21.     printf("***eroare****");
  22.  
  23.   char dir[20];
  24.   strcpy(dir,argv[2]);
  25.   strcat(dir,"/");
  26.   strcat(dir,argv[1]);
  27.   b = open(dir, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR);
  28.  
  29.   mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR);
  30.   int ibuff;
  31.   char wrbuff[20];
  32.   int i=0,j=0;
  33.   while(i<sizeof(buff)){
  34.     if(isdigit(buff[i])){
  35.       ibuff=buff[i]-'0';
  36.       if(ibuff % 2 == 0){
  37.     wrbuff[j]=buff[i];
  38.     j++;
  39.       }
  40.     }
  41.     i++;
  42.   }
  43.   i=0;
  44.   while(wrbuff[i])
  45.     i++;
  46.   printf("%s",wrbuff);
  47.   if(write(b, wrbuff, 3) == -1)
  48.     printf("***eroare***");
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement