Thread: Help! - FILE - sort alphabetically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    105

    Lightbulb Help! - FILE - sort alphabetically

    Hello everyone!
    I'm learning programming in C and now I have a some troubles with FILES. I searched a lot of tutorials in Google and YouTube but I really didn't understand how to solve some problems.

    I have to solve an exercise that says:
    In a File I have millon of names (they're not ordered alphabetically) and I have to print only the first 100 sorted alphabetically. The file is a .txt
    I can only use ONE array.


    I think I have to do this:
    First, I sort the first 100 names alphabetically and I save them in an array (alphabetically).
    Then, I go to the name 101 and I see if it's higher or lower than 100. If it's higher, the array continues like it was. If it's lower, I check it to the number 99. If it's higher, I put that name in the position 100 and I clean the name that was there. I can do that with a for.

    To compare the names, I think that "strcmp" would be perfect

    Can anyone help me with the code?

    Thank you VERY MUCH,
    Juan



    ps. I hope you understand what I wrote haha
    Last edited by juanjuanjuan; 02-12-2014 at 06:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  2. Arranging a file into alphabetical order.
    By Malachi in forum C Programming
    Replies: 18
    Last Post: 02-10-2009, 11:07 PM
  3. Replies: 4
    Last Post: 03-06-2008, 03:38 PM
  4. Binary File - Byte order / endian
    By chico1st in forum C Programming
    Replies: 27
    Last Post: 08-22-2007, 07:13 PM
  5. Header file include order
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 05-17-2006, 03:22 PM