Why is that problem?
For example, let's say you have records something like this:
Code:
typedef struct info
{
char name[21];
int order_num;
}info;
So you have simple structure and consisting of customer name and order number. Let's assume you have records like this stored in a binarny file. All you need to do is to open file in binary mode for reading, read sizeof info bytes (assuming records are written to the file that way) store it to a temp variable and check if that record matches certain criteria.
Here look at this code:
Code:
#include <stdio.h>
#include <string.h>
typedef struct info
{
char name[21];
int order_num;
}info;
int main(void)
{
info cust[3];
char buf[21];
int i,on;
info tmp;
FILE * fp;
/* first time uncommented*/
/* for (i = 0; i < 3; ++i)
{
sprintf(buf, "Cust. no. %d",i+1);
cust[i].order_num = i + 1;
strcpy(cust[i].name, buf);
}
fp = fopen("test.bin", "wb");
for (i = 0; i < 3; i++)
{
fwrite(&cust[i], sizeof(info), 1, fp);
}*/
/* first time commented*/
fp = fopen("test.bin","rb");
on = 2; /*we search order no. 2*/
while( (fread(&tmp, sizeof(info), 1, fp) == 1) && (tmp.order_num != on));
if (tmp.order_num == on)
{
printf("%s",tmp.name);
}
}
All error checking I'm leaving to you.
Just for demonstration purpose!
I hope this helps!