Arrange letters of the string alphabetically

This is a discussion on Arrange letters of the string alphabetically within the C Programming forums, part of the General Programming Boards category; hi guys im just new here and i really nid ur help as soon as possible... my friend ask me ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    7

    Arrange letters of the string alphabetically

    hi guys im just new here and i really nid ur help as soon as possible...
    my friend ask me to write a program in c for her programming subject, and I'm not really good at it.. I can do basics of c only. so please can you help me with this??... here's the problem.

    1)write a program that would allow users enter a string. arrange the letters of the string alphabetically using english alphabet.

    sample output:

    ENTER A STRING: COLEGIO DE DAGUPAN


    output: AACDDEEGGILNOOPU



    please help me make a code for that.

    i really dont know anything about sorting.

    thanks.

  2. #2
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    The rules don't permit me to post a solution.
    Last edited by abh!shek; 03-17-2008 at 09:44 AM.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not how it works here. You post the code you've got, and we help you get it better/right.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    But you can do this by getting the input into a string and then sorting it in increasing order of their ASCII values.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    is there a possible solution for the problem?

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by ama_cuber View Post
    is there a possible solution for the problem?
    Yes, there is.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    can i get a help? i really dont have an idea.. this is the last place i could go..

    just hit me some idea... please

  8. #8
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    http://www.newebgroup.com/academy/tables/ascii.htm

    Get the input in a string and sort the chars in increasing order of their ASCII values.

    .....or a better solution anyone else has...(?)

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This is quite clearly homework. As part of your class, book or whatever you are learning from, you should have had some training/explanation of sorting.

    You may miss your deadline, but for your own good, you should study the relevant material on "Sorting". You may even be able to find something on the subject via google, but don't ask us to "write your code for you".

    If you have a good reason for not going to class that day, or some such, then talk to your tutor and see if there is a way that you can get more time. If you were just not there for "bad" reasons, then maybe you deserve to be late?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    sorry but im not a computer related student that's why im asking for help.. just a simple code for this. by the way im a fine arts student.. thanks for the time.. and Im introduced to c programming just 3 days ago.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So may I ask who gave you the task to sort the letters?

    It seems very unlikely that you just came up with this on your own, whilst eating breakfast: "Ah, I know, I will ask someone if I can sort a string in C".

    It's not that we don't want to help you. But if I came to you and asked "Can you draw a picture for me?" and it was fairly obvious to you that the purpose of this was to give your picture in as the result of a school assignment or similar, would you think that this was a far thing to do? You are asking us to do your homework [or whatever classification it has - if you are studying C on your own time with no school or such involved then you are only cheating yourself - if you are cheating in school, then you are also cheating on your fellow students].

    --
    Mats
    Last edited by matsp; 03-17-2008 at 10:14 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    my best friend... that problem is the key to her final grade and she ask me to help her search some things or ask for help online for that one program. and that is why im here. look dude.. my bestfriend is a BA major and I really dont know that they have a programming subject. she know nothing about complicated programs.. sorry for breaking the rules here but I was just seeking for help. anyway thank you for the time.

  13. #13
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Pretend you have a string entered as above:

    COLEGIO DE DAGUPAN

    How would you sort this? There are many potential algorithms. Let's look at it one way.

    Find the lowest character in the entire string. In this case there are two 'A' characters at the 12th and 16th positions in the string. Take one of these, it doesn't matter which one, and swap it with the character at the beginning so we have:

    AOLEGIO DE DCGUPAN

    Now we do the same thing again but instead of starting at the beginning of the string while looking for the lowest character, we only consider the characters after the 'A' we just swapped which is the 'O'. The lowest is of course the other 'A' at the 16th position. So we again do a swap with the 'O' and the 'A' to arrive at:

    AALEGIO DE DCGUPON

    Now we start at the 'L' and search for the lowest character in the remaining string. The 'C' is the lowest so we can swap it with the 'L' and we get the following:

    AACEGIO DE DLGUPON

    We then start over again at the first 'E' character. The lowest of the remaining characters are the two 'D' characters so we swap one of them with the 'E' and arrive at:

    AACDGIO EE DLGUPON

    You should see how this particular algorithm works and be able to use it as a potential starting point for coming up with some code.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  14. #14
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    Thanks hk_mp5kpdw but I dont understand anything u said... I got your point but no idea on how to do that...

  15. #15
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    No one is going to do your (or your "friend's") homework on this board. Strike that, someone will likely come along and do it, but they should not.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

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