Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<sys/types.h> //Primitive system data types for abstraction of implementation-dependent data types.
- //POSIX Standard: 2.6 Primitive System Data Types <sys/types.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<stdlib.h>
- #include<stdio.h>
- #include<errno.h>
- main ( int argc, char* argv[] )
- {
- int fd;
- int r;
- int f;
- int TAM=10000;
- char cadena[TAM];
- int numBloque=80;
- int tam=numBloque;
- int i =1;
- if(argc < 2){
- perror("\nError %d numeros de parametros");
- exit(-1);
- }
- if((fd=open("archivo",O_CREAT|O_TRUNC|O_WRONLY,S_IRUSR|S_IWUSR))<0) {
- printf("\nError %d en crear",errno);
- perror("\nError en crear");
- exit(-1);
- }
- if((f=open(argv[1],O_WRONLY,S_IRUSR|S_IWUSR))<0){
- printf("\nError %d en open",errno);
- perror("\nError en open");
- exit(-1);
- }
- do{
- if(r=(read(f,cadena,numBloque))) {
- perror("\nError en read");
- exit(-1);
- }
- write(fd,("Bloque",i,"\n"),10);
- if(write(fd,cadena,tam)){
- perror("\nError en read");
- exit(-1);
- }
- if(tam!=TAM){
- tam+=tam;
- i++;
- write(fd,("Bloque",i,"\n"),10);
- }
- }while(r!=0);
- return 0;
- }
Add Comment
Please, Sign In to add comment