c - How to count the same products from a binary file and listing them with their numbers? -


i'm reading products binary file. when i'm reading these products, i'm counting repetition of same products. @ end,i'm listing products , numbers.

void product_counting_listing(file *fileptr) {  product p;  while(!feof(fileptr)) {     fread(&p.p_code,sizeof(product),1,fileptr);     ?? }  rewind(fileptr); while(!feof(fileptr)){     printf("product code  number of product\n");     printf("-------- --------");     fread(&p.p_code,sizeof(product),1,fileptr);     printf("%d %d",p.p_code,?)  } 

any ideas counting same products , listing them?

while(!feof(fileptr)) not approach pointed @joachim pileborg. can find fruitful information why @ why “while ( !feof (file) )” wrong?

now assuming file contains multiple product structure information, simple approach read structures be

int bytesread = 0; while((bytesread = fread(&p.p_code,sizeof(product),1,fileptr)) > 0){     //print product information     //check duplicate products     memset(&p, '\0', sizeof(product)); } 

in last line, resetting product structure reuse next read.

now in order identify duplicate products, need maintain list of products read previously. , after reading each product must iterate on previous products find duplicate ones. maintain list of previous products, can use link-lists. or how want that


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -