Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <errno.h>
- #include <limits.h>
- #include <string.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #define SECTOR_SIZE 4096
- char numeFisierSursa[PATH_MAX],numeFisierDestinatie[PATH_MAX];
- char buffer[SECTOR_SIZE],comanda[10];
- int bytes_read;
- char c1,c2;
- int vocala(char c)
- {
- return (strchr("AEIOUaeiou",c)!=NULL);
- }
- int main(int argc,char **argv)
- {
- FILE *fptr1,*fptr2;
- printf("Nume fisier sursa : ");
- scanf("%s",numeFisierSursa);
- printf("Nume fisier destinatie : ");
- scanf("%s",numeFisierDestinatie);
- int f1=open(numeFisierSursa,O_RDONLY);
- if(f1<0)
- {
- perror("Error on opening file");
- exit(1);
- }
- int f2=open(numeFisierDestinatie,O_WRONLY);
- if(f2 > 0 )
- {
- printf("Doriti sa suprascrieti continutul ? da/nu ");
- scanf("%10s",&comanda);
- if(strcmp(comanda,"da")!=0)
- {
- printf("\nNu ati acordat permisiunea");
- exit(5);
- }
- open(numeFisierDestinatie,O_WRONLY | O_TRUNC);
- chmod(numeFisierDestinatie,S_IRUSR | S_IWUSR);
- }
- while(1){
- bytes_read = read(f1,buffer,SECTOR_SIZE);
- if(bytes_read == 0)
- break;
- if(bytes_read == -1)
- {
- perror("error on writing");
- exit(6);
- }
- for(int i=0;buffer[i]!=NULL;i++)
- if(vocala(buffer[i])>0)
- {
- for(int j=i;buffer[j]!=NULL;j++)
- buffer[j]=buffer[j+1];
- i--;
- }
- if(write(f2,buffer,SECTOR_SIZE)<0)
- {
- perror("Error on writing");
- exit(7);
- }
- }
- if(close(f1)==-1 || close(f2)==-1)
- {
- perror("Error on closing files");
- exit(9);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement