#include #include #include #include bool leer_numero(FILE* f, int* seek_lectura, int16_t* valor) { fseek(f, *seek_lectura, SEEK_SET); char aux[2]; if ( fread(aux, 2, 1, f) == 0 ) return false; memcpy(valor, aux, 2); *seek_lectura = ftell(f); return true; } void escribir_numero(FILE* f, int* seek_escritura, int16_t valor) { fseek(f, *seek_escritura, SEEK_SET); fwrite(&valor, 2, 1, f); *seek_escritura = ftell(f); } int main() { FILE* f = fopen("a.bin", "r+"); if (!f) return -1; int seek_lectura = 0; int seek_escritura = 0; size_t pos = 0; int16_t valor; while ( leer_numero(f, &seek_lectura, &valor) ) { valor += pos; ++pos; escribir_numero(f, &seek_escritura, valor); } fclose(f); return 0; }