Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <unistd.h>
- int main(int argc, char *argv[]){
- char input[10], output[10], ch;
- int smallch=0, bigch=0, digits=0, apparitions=0, total=0;
- int f1,f2;
- strcpy(input, argv[1]);
- strcpy(output, argv[2]);
- ch=argv[3][0];
- f1=open(argv[1],O_RDONLY);
- f2=open(argv[2],O_WRONLY);
- if(f1==-1)
- printf("cannot open input file\n");
- if(f1==-1)
- printf("cannot open output file\n");
- //read file
- char car;
- int r;
- while((r=read(f1,&car,1))>0){
- if(car>=97&&car<=122){
- smallch++;
- }
- else if(car>=65&&car<=90){
- bigch++;
- }
- else if(car>=48&&car<=57){
- digits++;
- }
- if(car==ch)
- apparitions++;
- total++;
- }
- //printf("%d %d %d %d", smallch,bigch,apparitions,total);
- char string[50],aux[5];
- int w;
- itoa(smallch,aux,10);
- strcpy(string,"numar litere mici: ");
- strcat(string, aux);
- strcat(string, "\n");
- w=write(f2,string,strlen(string));
- itoa(bigch,aux,10);
- strcpy(string,"numar litere mari: ");
- strcat(string, aux);
- strcat(string, "\n");
- w=write(f2,string,strlen(string));
- itoa(digits,aux,10);
- strcpy(string,"numar cifre: ");
- strcat(string, aux);
- strcat(string, "\n");
- w=write(f2,string,strlen(string));
- itoa(apparitions,aux,10);
- strcpy(string,"numar aparitii caracter: ");
- strcat(string, aux);
- strcat(string, "\n");
- w=write(f2,string,strlen(string));
- itoa(total,aux,10);
- strcpy(string,"dimensiune fisier: ");
- strcat(string, aux);
- w=write(f2,string,strlen(string));
- if(close(f1)<0){
- perror("eroare inchidere fisier citire");
- exit(1);
- }
- if(close(f2)<0){
- perror("eroare inchidere fisier scriere");
- exit(1);
- }
- //f=close(f1);
- //g=close(f2);
- //return 0;
- }
Add Comment
Please, Sign In to add comment