Link to home
Start Free TrialLog in
Avatar of Blkangel
Blkangel

asked on

Searching in binary files

I would like to implement a dictionary in a binary file and I have heard that you can search in a binary file by setting something like locators in the file itself. For example if i were looking for experts. I would look for the location of the letter in the file and just jump to that location and so on and so forth. The question is what I am saying possible or not and if possible how can i do that.
Avatar of TDC_LuCiFeR
TDC_LuCiFeR
Flag of Ireland image

Yes u can,  firstly you will have to open the file and read in each byte and compare it to the first letter u are looking for,  

char x, yourchar ="e";  // the char u are looking for
FILE *fp;  //file pointer


fp = fopen("File.exe","rb");   open the file in binary mode

while(x != yourchar)
{
     x = getc(fp);  //get the char pointer to by the file pointer
}

// something like this,  i have no compiler now.
Next once u find the character u are looking for within the file u can use these to set the pointer
SEEK_SET
SEEK_CUR
SEEK_END


Have a look on this site
http://computer.howstuffworks.com/c17.htm




Avatar of jkr
Denpends on the size of the file and the way you are organizing the data within it. I'd actually set up some form of structured storage like an index that points to content inside the binary file, e.g.

struct dict_unit {

   char acTerm [ MAX_TERM];
   unsigned long ulTranslatedUnit; // points to offs. in file where the translation can be found
};
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial