Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "string.h"
  4. #include "unistd.h"
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <ctype.h>
  9.  
  10. #define blocksize 4096
  11. int main(int argc, char *argv[]){
  12. char *file, *dir, *outfile;
  13. if(argc != 3){
  14. printf("Usage: %s file dir",argv[0]);
  15. exit(-2);
  16. }
  17. else{
  18. file = (char*)malloc(sizeof(char)*strlen(argv[1])+1);
  19. outfile = (char*)malloc(sizeof(char)*(strlen(argv[1])+strlen(argv[2]))+1);
  20. dir = (char*)malloc(sizeof(char)*strlen(argv[2])+1);
  21. strcpy(file,argv[1]);
  22. strcpy(dir,argv[2]);
  23. strcat(outfile,dir);
  24. strcat(outfile,file);
  25. }
  26. float procent, majuscule = 0, litere = 0;
  27. char buffer[blocksize], bufferout[blocksize];
  28.  
  29. int finp = open(file,O_RDONLY);
  30. int fout = open(outfile,O_WRONLY|O_CREAT,S_IWUSR|S_IRUSR);
  31. int readval;
  32. while(1){
  33. readval = read(finp, buffer, blocksize);
  34. litere+=readval;
  35. for(int i = 0; i < readval; i++)
  36. if(isupper(buffer[i]))
  37. majuscule++;
  38. if(readval != blocksize)
  39. break;
  40. }
  41. procent = majuscule/litere*100;
  42.  
  43. struct stat *struct_buf;
  44. struct_buf = (struct stat*)malloc(sizeof(struct stat));
  45. stat(argv[0],struct_buf);
  46. sprintf(bufferout,"Procentul este %f\%; UID = %u\n",procent,struct_buf->st_uid);
  47. printf("%s",bufferout);
  48. write(fout,bufferout,strlen(bufferout));
  49.  
  50.  
  51. if(symlink(outfile,"mylink")!=0)
  52. exit(-3);
  53. close(finp);
  54. close(fout);
  55. free(file);
  56. free(dir);
  57. free(outfile);
  58. free(struct_buf);
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement