Thread: is there a C function that would sort letters?

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

    is there a C function that would sort letters?


  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Not really. What are you trying to do exactly?
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2
    Originally posted by Cshot
    Not really. What are you trying to do exactly?
    well, i have a card program where i would have to sort the deck. I could sort out the numbers but I can't seem to sort out suits (D,C,H,S).

    For example, my output would be:

    H S C D D H C S S D C H ...
    1 1 1 1 2 2 2 2 3 3 3 3 ...

  4. #4
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I would try assigning number values to each letter. ASCII should work.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Depends on your implementation. You could use numbers for all cards (1-13) to make them sortable, and later convert 1, 11, 12 & 13 to letters (in the output).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Comparing characters and numbers should almost be the same:

    Code:
    int cardValue;
    char suit;
    
    // hypothetical example
    if(cardValue > 3)
       // do stuff
    
    if(suit > 'H')
       // do stuff
    Likewise, you can set all cards to values between 1-52. The suit would depend on the card number range, and the card value would be mod 4. Or you can create a struct with a suit and value attribute. Like what Magos said, you can convert to letters when outputting.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Compile problem: sort() cannot be used as a function!?
    By ac251404 in forum C++ Programming
    Replies: 2
    Last Post: 06-01-2006, 12:58 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Replies: 10
    Last Post: 09-15-2004, 01:00 PM