Topic: File I/O
Author: Dominic Catellier <encyclophonia@hotmail.com>
Date: 1998/05/04 Raw View
I just really need help with file I/O...
It's been a while since I've tried to edit a certain byte of a file.
Here's my code, if someone can tell me how to be able to change one
specific byte of a file. Mine compiles, but runs wrong, first it wont
write to that byte, and second, it doesn't write the good stuff. Anyway,
here's what I've got:
#include <io.h>
#include <stdio.h>
#include <iostream.h>
int main(void)
{
int allAttribute; // The new attributes value
char thecharvariable; // The variable to show that byte
cout << "Give me a new variable to add to all attributes";
cout << "\nIf you want it unchanged, just enter the old value.\n";
cin >> allAttribute; // Give the new attribute
FILE *me; // The file
me = fopen( "d:\\program\\game\\diablo\\weapons\\king's~1.itm", "r+"
);
if( me == NULL ) {printf("Error 1"); abort(); } // Error message
fseek( me, 288, SEEK_SET ); // Seek the byte
fscanf( me, "%c", &thecharvariable ); // Scan that byte and give it
a name
fprintf( me, "%d", allAttribute ); // Print that byte also the
problem
printf("Add to all attributes: %d", thecharvariable);
fclose(me);
}
Anyway, i hope to get an answer soon
Dominic Catellier
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]