Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<sys/types.h>
  5. #include<sys/stat.h>
  6. #include<fcntl.h>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. if(argc!=2)
  11. printf("usage : <exec> file dir.\n");
  12. char buffer[20];
  13. int nr_cifre=0;
  14.  
  15. int file1=open(argv[1],O_RDONLY);
  16. int nr_caractere=0;
  17.  
  18. while(read(file1,&buffer,sizeof(char)))
  19. {
  20. if(isdigit(buffer[0]))
  21. {
  22. nr_cifre++;
  23. printf("%c", buffer[0]);
  24. }
  25. nr_caractere++;
  26. }
  27.  
  28. close(file1);
  29. printf("\n");
  30. printf("In fisierul dat ca argument sunt %d cifre.", nr_cifre);
  31.  
  32. int pf = creat("/home/student/noulfisier", S_IRUSR|S_IWUSR);
  33. sprintf(buffer,"In fisierul dat ca argument sunt %d cifre.", nr_cifre);
  34. write(pf,buffer,strlen(buffer));
  35.  
  36. struct stat s;
  37. int i=lstat(argv[1],&s);
  38. sprintf(buffer,"Grup ID: %d",s.st_gid);
  39. write(pf,buffer,strlen(buffer));
  40. symlink("home/student/noulfisier","./mylink");
  41.  
  42. close(pf);
  43. printf("\n");
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement