I'm working in C right now and I'm reading a disk image that uses the FAT12 system. In the command line, I accept the name of a file to copy from the disk image to the local folder. Here's my question, when I'm traversing through all the bytes that I need to fetch for a particular file that I will be copying to the local folder, what function(s) should use to write those bytes to my local file?
By the way, the files that need to be copied from the disk may be PDF, .txt, etc.
As of now, I use the below to open (create) the file locally and then the function below it to write bytes to that file (this function is where I think the problem lies) There's a lot more code that actually traverses through the bytes in the FAT12, but I simply need to know what I'm doing wrong during the write:
FILE *file = fopen(arg[2],"wb"); //To create the file on the local folder
fprintf(file,"%#04x ",buffer[index]); //Write a byte from the file that is being copied to the local file from the disk image
My code works perfectly in regards to getting the appropriate bytes from the files that I am copying, but for some reason, the .PDF files do not open, and the .txt files only display the copied bytes (no text).
Any advice would be greatly appreciated!