File data sorting

This is a discussion on File data sorting within the C Programming forums, part of the General Programming Boards category; Any tips on how to sort a file with random numbers using the fwrite, fseek, and fscan without using an ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    File data sorting

    Any tips on how to sort a file with random numbers using the fwrite, fseek, and fscan without using an array? I want to be able to make a copy of the file, sort it in increasing order, and print out the sorted data.

    Thanks.

  2. #2
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Thumbs up

    One possibility that i can see to sort the recs in a file with out using arrays is that u create a temporary file (initially blank).
    U first scan the entire source file for the smallest valued record (and fix an index there). Once the file is scanned, pick the indexed record and dump it in the other file. Repeat the process for the next record and so on.

    Yeah...this is a very search-intensive process, but thats all i can think of right now...

    Happy coding...

    -Harsha.
    Help everyone you can

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Read the file into a binary tree and then print it out to the new file with an in-order traversal. The file is sorted because binary trees by nature sort the data inserted into them.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 05:44 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21