what's wrong with the program?

i would like to write a console program that replace some lines in a existing bin file,
the command for the program should be "xxx desire.bin startbyte endbyte value",
i.e write cmd in msdos "fillbin a.bin 100 200 255" will fill a.bin address(100-200) with FF.

and i tried to write like this:


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
FILE *fptr;
if( argc!=5 ) //program locationfile start end value
{
printf( "\nUsage: FillBin File Start End DesireValue!\n" );
exit(1);
}

if (start>=end){
printf("the end should larger than start");
exit(1);
}
else {

fseek(fptr,start,0); //fptr move to the starting address

for(int i=0;i<=end-start;i++)
fwrite(&value, sizeof value,1, fptr);

fclose(fptr);
exit(1);
}

however, when i execute to existing file, it just overwrite it instead....

what i want is to amend the .bin file....

could anyone help me?????
THX!
Last edited on
Where's your fopen() for the fptr?
Topic archived. No new replies allowed.