So I managed to get my hands on a license for the proprietary program to convert the data files into a binary format, meaning a .bin file.
If I use a hex editor to look at the data, the number 21376
in ASCII Format: (hex) 32 31 35 36 36 (5 bytes)
in Binary Format: (hex) 53 80 (2 bytes)
Hopefully, this clarifies what I've been trying to describe. I actually see ~50% file reduction size with a binary format in comparison to ASCII.
So now that I successfully got it into a Binary format, but I still have the problem of not knowing how to manipulate the data in binary. I know you mentioned just look up the library functions, but if you could help point me in the right direction that would be great.
In the binary file (hex editor), I have a 16 bit word followed by 0d 0a which are ascii for carriage return and newline. I want to remove the carriage return and newline so my binary file will just continuously have the 16 bit words one after the other. So basically I need to delete every other 16 bits in the binary file. I've tried reading in one byte at a time with fread and using fwrite to write to a new .bin file every other 2 bytes since there is a possibility the data is 0d 0a.
Are there buffer issues I should be aware of when using
fread() because I'll cycle through the opened binary file with a
while(!feof(fp_heimData)) , but when it finishes I only see 1 kb worth of data when it should be closer to 3000 kb. The original file size is 6000 kb.
and here's the c code I've written:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
//initialize variables
int count = 0;
char * hex_test;
FILE *fp_readBin, *fp_writeBin;
//open binary file to read and binary file to write
if((fp_readBin = fopen( "Ftrans.Bin", "r" ))==NULL) {
printf("cannot open file");
exit(1);
}
if((fp_writeBin = fopen( "Ftrans2.Bin", "w" ))==NULL) {
printf("cannot open file");
exit(1);
}
//remove all character codes
hex_test = (char*) malloc (sizeof(char));
/*while(!feof(fp_readBin)){
fread(hex_test,1,1,fp_readBin);
if(count == 0 || count == 1){
fwrite(hex_test,1,1,fp_writeBin);
}
if (count == 3)
count = 0;
count++;
}*/
//testing to see if it will cycle through the entirety of the file
while(!feof(fp_readBin)){
fread(hex_test,1,1,fp_readBin);
if(*hex_test != 0x0d || *hex_test != 0x0a){
fwrite(hex_test,1,sizeof(hex_test),fp_writeBin);
}
}
printf("finished\n");
fclose(fp_readBin);
fclose(fp_writeBin);
free(hex_test);
return 0;
}
I've been told PERL works great for file manipulation, but I would prefer to stay in C to make it easier to work with other programmers once I finish up my internship.
Thanks again! Much appreciated.