Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Escriba una aplicación C que modifique el archivo a.dat eliminando los bytes
- mayores a 0xC3.
- */
- #include <stdio.h>
- #include <unistd.h>
- int leer_byte(FILE* f, int* seek_lectura) {
- fseek(f, *seek_lectura, SEEK_SET);
- int c = fgetc(f);
- *seek_lectura = ftell(f);
- return c;
- }
- void escribir_byte(FILE* f, int* seek_escritura, unsigned char c) {
- fseek(f, *seek_escritura, SEEK_SET);
- fputc(c, f);
- *seek_escritura = ftell(f);
- }
- int main() {
- int seek_lectura = 0;
- int seek_escritura = 0;
- FILE* f = fopen("a.dat", "r+");
- if (!f) return -1;
- int c;
- unsigned char character;
- while ( (c = leer_byte(f, &seek_lectura)) != EOF ) {
- character = (unsigned char)c;
- if (character <= 0xC3) {
- escribir_byte(f, &seek_escritura, character);
- printf("DEBUG: lo escribo\n");
- } else {
- printf("DEBUG: no lo escribo\n");
- }
- }
- fclose(f);
- truncate("a.dat", seek_escritura);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment