sorting file

Reply

Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

sorting file

 
0
  #1
May 11th, 2004
hello,
i want to sort a file and i don't know how to put the data from a certain field of the file in a vector, sort it and then put it back in the file.
here's what i've done.

  1. FILE *file;
  2. struct catalog{char 1rst_field,2nd_field,3rd_field}name,v[100];
  3.  
  4. //here i put the data in the file
  5.  
  6. typedef int(*fcmp)(const void*,const void*)
  7. cmp1rst_field(catalog a1,catalog a2)
  8. {return a1.1rst_field-a2.1rst_field}
  9. int a[100],n=100,i;
  10.  
  11. void sort()
  12. {
  13. while(!feof(file))
  14.  
  15. //here i'd have to put the data from 1rst_field in a[i];i++;
  16.  
  17. qsort(&a[0],n,sizeof (int),(fcmp)cmp1rst_field)
  18. }
i'd appreciate any help with this sorting algorithm or another that would be simpler.thank you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC