Red de conocimiento informático - Aprendizaje de código fuente - Programación de archivos abiertos

Programación de archivos abiertos

#¿Incluir? ltstdio.h gt

#¿Contiene? ltsys/types .h gt;

#Contiene? ltsys/stat . h gt;

¿#Contiene? ltfcntl.h gt

#¿Incluir? ltunistd.h gt

#¿Incluir? ltstring.h gt

int? principal()? {?

int? ¿fd? =?-1;?

fd? =?Open("zhidao_561804018.dat",O_CREAT?|?TRUNC?|?O_RDWR,?0666);

¿Si? (fd? lt? 0)?{

error("on");

¿Regresar? -1;?

}?

¿Ciel? buff[64];

strcpy(buff,? "¡Hola! ¿Yo? ¿Yo? ¿Escribiendo? ¿A dónde ir? ¿Esto? ¡Archivo!"); ¿Contar? =?strlen(buff);

¿Si? (escribir (fd,? buff? ¿cuenta)? ¿lt? 0)?{

error("escribir");

¿Regresar? -1;?

}?

¿Y si? (lseek(fd,?0,?SEEK_SET)?lt?0)?{

perror(" lseek ");

¿Regresión? -1;?

}?

¿Y si? (leer(fd,?buff?10)?lt?0)?{

error("leer");

¿Regresar? -1;?

}?

buff[10]? =?0x00

printf("s\n ", buff);

¿Si? (fd? gt? 0)?{

Cerrar(FD);

fd? =?-1;?

}?

¿Volver? 0;

}