Advertisement
Guest User

setAG posix

a guest
Mar 30th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <errno.h>
  4. #include <limits.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include <stdlib.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10.  
  11. #define SECTOR_SIZE 4096
  12.  
  13. char numeFisierSursa[PATH_MAX],numeFisierDestinatie[PATH_MAX];
  14. char buffer[SECTOR_SIZE],comanda[10];
  15. int bytes_read;
  16. char c1,c2;
  17.  
  18. int vocala(char c)
  19. {
  20. return (strchr("AEIOUaeiou",c)!=NULL);
  21. }
  22.  
  23. int main(int argc,char **argv)
  24. {
  25. FILE *fptr1,*fptr2;
  26.  
  27. printf("Nume fisier sursa : ");
  28. scanf("%s",numeFisierSursa);
  29.  
  30. printf("Nume fisier destinatie : ");
  31. scanf("%s",numeFisierDestinatie);
  32.  
  33. int f1=open(numeFisierSursa,O_RDONLY);
  34.  
  35. if(f1<0)
  36. {
  37. perror("Error on opening file");
  38. exit(1);
  39. }
  40.  
  41. int f2=open(numeFisierDestinatie,O_WRONLY);
  42.  
  43. if(f2 > 0 )
  44. {
  45. printf("Doriti sa suprascrieti continutul ? da/nu ");
  46. scanf("%10s",&comanda);
  47. if(strcmp(comanda,"da")!=0)
  48. {
  49. printf("\nNu ati acordat permisiunea");
  50. exit(5);
  51. }
  52. open(numeFisierDestinatie,O_WRONLY | O_TRUNC);
  53. chmod(numeFisierDestinatie,S_IRUSR | S_IWUSR);
  54. }
  55.  
  56.  
  57. while(1){
  58. bytes_read = read(f1,buffer,SECTOR_SIZE);
  59. if(bytes_read == 0)
  60. break;
  61. if(bytes_read == -1)
  62. {
  63. perror("error on writing");
  64. exit(6);
  65. }
  66.  
  67. for(int i=0;buffer[i]!=NULL;i++)
  68. if(vocala(buffer[i])>0)
  69. {
  70. for(int j=i;buffer[j]!=NULL;j++)
  71. buffer[j]=buffer[j+1];
  72. i--;
  73. }
  74.  
  75.  
  76. if(write(f2,buffer,SECTOR_SIZE)<0)
  77. {
  78. perror("Error on writing");
  79. exit(7);
  80. }
  81.  
  82. }
  83.  
  84. if(close(f1)==-1 || close(f2)==-1)
  85. {
  86. perror("Error on closing files");
  87. exit(9);
  88. }
  89.  
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement