Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Escribir un programa ISO C que procese el archivo "nros1byte.dat" sobre si
- mismo, eliminando los bytes multiplos de 6.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <stdbool.h>
- char leer_byte(FILE* f, int* seek_lectura) {
- fseek(f, *seek_lectura, SEEK_SET);
- char c = fgetc(f);
- *seek_lectura = ftell(f);
- return c;
- }
- void escribir_byte(FILE* f, int* seek_escritura, char c) {
- fseek(f, *seek_escritura, SEEK_SET);
- fputc(c, f);
- *seek_escritura = ftell(f);
- }
- bool es_multiplo_6(char c){
- return ((c % 6) == 0);
- }
- int main() {
- FILE* f = fopen("nros1byte.dat", "r+");
- if (!f) return -1;
- int seek_lectura = 0;
- int seek_escritura = 0;
- char c;
- while ( (c = leer_byte(f, &seek_lectura)) != EOF ) {
- if (!es_multiplo_6(c))
- escribir_byte(f, &seek_escritura, c);
- }
- fclose(f);
- truncate("nros1byte.dat", seek_escritura);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement