0

I was trying to do a program that analyzes poker hands, however I am extremely confused and I don't know where to start. The suits are represented by the letters C(clubs), D(diamonds), H(hearts) and S(spades).

The value of the cards is represented by the numbers and the letters A(ace), 2, 3, 4, 5, 6, 7, 8, 9, T(ten), J(jack), Q(queen) and K(king).

The program is supposed to receive input like AS KC QC JH 9D.

But the difficult part is that it should be able to receive 5, 7, 9 or 10 cards (strings with 2 chars).

Note: each card is made of two chars (example: 2C). Thank you in advance :)

  • Do you have any code written already, or are you asking for a solution with a complete program? – rtx13 Mar 31 '20 at 02:09
  • 1
    I don't have anything, I don't even know where to start – Ana Ferreira Mar 31 '20 at 02:13
  • Do you have any programming experience in any computer language? – rtx13 Mar 31 '20 at 02:15
  • I know a little of C, but I don't know how to take the input and differentiate the cards (strings of 2 chars). Especially because you can input 5, 7, 9 and 10 cards. – Ana Ferreira Mar 31 '20 at 02:21
  • A card should be represented as a `struct` with a suit (0 to 3) and a value (2 to 14). The input can be stored in an array of those structs. And the first task in the code is to convert the letters to numbers, e.g. T=10, J=11, etc. and S=0, H=1, etc. – user3386109 Mar 31 '20 at 02:26
  • Is each hand (set of _n_ cards) passed in as a single string of 2*_n_ characters? – rtx13 Mar 31 '20 at 02:27
  • Yes with a space in between cards – Ana Ferreira Mar 31 '20 at 02:30
  • I'd start with [`getline`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html). – aschepler Mar 31 '20 at 02:56

1 Answers1

2

I will offer incremental suggestions in this answer:

  1. To determine how many cards are in the hand/set: you can call strlen(string) to count the number of characters in the string.

  2. Once you know how many cards are there, you can use a switch statement: switch(number_of_cards) { ... } to branch the processing logic into distinct cases.

rtx13
  • 2,580
  • 1
  • 6
  • 22