I am having trouble copying from a binary file and writing to a text file. I have written a program that is capable of copying from a text file and writing to a binary file but I cannot do the reverse.
Here is my function that I am having issues with:
void CopyBin2Text(char* rafname, char* txtname)
{
FILE * fraf = fopen(rafname,"rb");
FILE * ftxt = fopen(txtname,"r+");
//READ FROM BINARY FILE
struct PERSON p;
int ByteOfBin;
printf("ID \t NAME \t\t BALANCE \n");
printf("---------------------------------------\n");
when I run my program it stops here after printing the above statement
while(!feof(fraf))
{
fscanf(fraf, "%d %s %f", &p.ID, p.name, &p.balance);
ByteOfBin = ((p.ID/10-1)*sizeof(p));
fseek(ftxt,ByteOfBin, SEEK_SET);
fwrite((char *)&p, sizeof(p), 1, ftxt);
}
fclose(fraf);
fclose(ftxt);
}
Another issue that I have noticed is that the text file becomes to large to open. The result is that I have to delete the text file and create it again. Can anyone explain what is causing this to occur?