Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. char* input_file;
  11. char* stats_file;
  12. char* c = (char *) calloc(100, sizeof(char));
  13. char* buff = (char*) calloc(200, sizeof(char));
  14. int filedesc;
  15. int i, i_max;
  16. char option;
  17.  
  18. int numar_majuscule = 0;
  19. int numar_cifre = 0;
  20. int hard_links = 0;
  21. int i_nodes = 0;
  22. int size = 0;
  23. int nbytes;
  24. struct stat fileStat;
  25.  
  26. if (argc != 3 && argc != 4) {
  27. printf("EROARE BOSS");
  28. return 1;
  29. }
  30.  
  31. input_file = argv[1];
  32. stats_file = argv[2];
  33. option = argv[3];
  34.  
  35. if (option == 's'){
  36. unlink(input_file);
  37. symlink(input_file, stats_file);
  38. }
  39. if (option == 'h'){
  40. unlink(input_file);
  41. link (input_file, stats_file);
  42. }
  43.  
  44. if(lstat(input_file,&fileStat) < 0)
  45. return 1;
  46. filedesc = open(input_file, O_RDONLY);
  47. if(filedesc < 0)
  48. return 1;
  49. hard_links = fileStat.st_nlink;
  50. i_nodes = fileStat.st_ino;
  51. size = fileStat.st_size;
  52. while(i_max = read(filedesc, c, 100)) {
  53. for(i=0; i<i_max; i++){
  54. if (c[i] >= 'A' && c[i] <= 'Z')
  55. numar_majuscule++;
  56. if (c[i] >= '0' && c[i] <= '9')
  57. numar_cifre++;
  58. }
  59. }
  60. close(filedesc);
  61.  
  62. filedesc = open(stats_file, O_WRONLY);
  63. sprintf(buff, "Numarul de cifre: %d\nNumarul de majuscule: %d\nhard_links: %d\ni_nodes: %d\nsize: %d", numar_cifre, numar_majuscule, hard_links, i_nodes, size);
  64. nbytes = strlen(buff);
  65. write(filedesc, buff, nbytes);
  66. close(filedesc);
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement