Guest User

Untitled

a guest
Mar 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include<sys/types.h> //Primitive system data types for abstraction of implementation-dependent data types.
  2. //POSIX Standard: 2.6 Primitive System Data Types <sys/types.h>
  3. #include<sys/stat.h>
  4. #include<fcntl.h>
  5. #include<stdlib.h>
  6. #include<stdio.h>
  7. #include<errno.h>
  8.  
  9.  
  10. main ( int argc, char* argv[] )
  11. {
  12. int fd;
  13. int r;
  14. int f;
  15. int TAM=10000;
  16. char cadena[TAM];
  17. int numBloque=80;
  18. int tam=numBloque;
  19. int i =1;
  20.  
  21. if(argc < 2){
  22. perror("\nError %d numeros de parametros");
  23. exit(-1);
  24. }
  25.  
  26. if((fd=open("archivo",O_CREAT|O_TRUNC|O_WRONLY,S_IRUSR|S_IWUSR))<0) {
  27. printf("\nError %d en crear",errno);
  28. perror("\nError en crear");
  29. exit(-1);
  30. }
  31. if((f=open(argv[1],O_WRONLY,S_IRUSR|S_IWUSR))<0){
  32. printf("\nError %d en open",errno);
  33. perror("\nError en open");
  34. exit(-1);
  35. }
  36.  
  37. do{
  38.  
  39. if(r=(read(f,cadena,numBloque))) {
  40. perror("\nError en read");
  41. exit(-1);
  42. }
  43. write(fd,("Bloque",i,"\n"),10);
  44. if(write(fd,cadena,tam)){
  45. perror("\nError en read");
  46. exit(-1);
  47. }
  48. if(tam!=TAM){
  49. tam+=tam;
  50. i++;
  51. write(fd,("Bloque",i,"\n"),10);
  52. }
  53. }while(r!=0);
  54.  
  55. return 0;
  56. }
Add Comment
Please, Sign In to add comment