Advertisement
C_Razvan

LAB SO S4

Oct 14th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #define BLOCK_SIZE 4096
  5.  
  6. int main(int argc , char *argv[])
  7. {
  8.  
  9. char buf[BLOCK_SIZE],res[BLOCK_SIZE];
  10. int i=0,nchar,nrmaj=0,nrcif=0;
  11. if (argc != 3)
  12. {
  13. perror("N-AI DAT DOUA ARGUMENTE");
  14. exit(1);
  15. }
  16. printf("%d\n",argc);
  17. int fd = open(argv[1],O_RDONLY);
  18.  
  19. if(fd!=-1)
  20. {
  21. while(nchar=read(fd,buf,BLOCK_SIZE))
  22.  
  23. for(i=0;i<nchar;i++)
  24. {
  25. if(buf[i]>='A'&& buf[i]<='Z')
  26. nrmaj++;
  27. if(buf[i]>='0'&&buf[i]<='9')
  28. nrcif++;
  29. }
  30. }
  31. else
  32. {
  33. perror ("Nu am putut deschide fisierul de input ");
  34. exit(2);
  35. }
  36. printf("sunt %d majuscule in texte.txt \n",nrmaj);
  37. printf("sunt %d cifre in texte.txt \n",nrcif);
  38. close(fd);
  39. int fd2 = open(argv[2],O_WRONLY);
  40.  
  41. int wbuf = sprintf(res,"Nr Majuscule %d \n Nr Cifre %d \n",nrmaj,nrcif);
  42. write(fd2,res,wbuf);
  43. close(fd2);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement