943,919 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5256
  • C RSS
May 11th, 2004
0

sorting file

Expand Post »
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.
Similar Threads
Team Colleague
Reputation Points: 55
Solved Threads: 3
Junior Poster
meabed is offline Offline
139 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: C craps game
Next Thread in C Forum Timeline: Displaying Data in C programmming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC