Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #define BLOCK_SIZE 4096
- int main(int argc , char *argv[])
- {
- char buf[BLOCK_SIZE],res[BLOCK_SIZE];
- int i=0,nchar,nrmaj=0,nrcif=0;
- if (argc != 3)
- {
- perror("N-AI DAT DOUA ARGUMENTE");
- exit(1);
- }
- printf("%d\n",argc);
- int fd = open(argv[1],O_RDONLY);
- if(fd!=-1)
- {
- while(nchar=read(fd,buf,BLOCK_SIZE))
- for(i=0;i<nchar;i++)
- {
- if(buf[i]>='A'&& buf[i]<='Z')
- nrmaj++;
- if(buf[i]>='0'&&buf[i]<='9')
- nrcif++;
- }
- }
- else
- {
- perror ("Nu am putut deschide fisierul de input ");
- exit(2);
- }
- printf("sunt %d majuscule in texte.txt \n",nrmaj);
- printf("sunt %d cifre in texte.txt \n",nrcif);
- close(fd);
- int fd2 = open(argv[2],O_WRONLY);
- int wbuf = sprintf(res,"Nr Majuscule %d \n Nr Cifre %d \n",nrmaj,nrcif);
- write(fd2,res,wbuf);
- close(fd2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement