473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Storing info for cards

Hi All,

I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:

"
You have been asked to write a program for a card playing friend. How
would you store information about playing cards? For example how would
you store the fact that a certain card is the 7 of diamonds? (You may
use more than one variable if you wish)
"

All help welcome.
Thanks in advance.

Radith

Nov 15 '05 #1
26 1928

"Radith" <ra****@xtra.co.nz> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi All,

I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:

"
You have been asked to write a program for a card playing friend. How
would you store information about playing cards? For example how would
you store the fact that a certain card is the 7 of diamonds? (You may
use more than one variable if you wish)
"

All help welcome.
Thanks in advance.

Radith


enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
enum faces {ACE = 1, JACK = 11, QUEEN, KING};

struct card
{
unsigned int rank;
unsigned char suit;
};

card c = {7, DIAMONDS};
-Mike
Nov 15 '05 #2
Mike Wahler wrote:
"Radith" <ra****@xtra.co.nz> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi All,

I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:

"
You have been asked to write a program for a card playing friend. How
would you store information about playing cards? For example how would
you store the fact that a certain card is the 7 of diamonds? (You may
use more than one variable if you wish)
"

All help welcome.
Thanks in advance.

Radith


enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
enum faces {ACE = 1, JACK = 11, QUEEN, KING};

struct card
{
unsigned int rank;
unsigned char suit;
};

card c = {7, DIAMONDS};


struct card c = {7, DIAMONDS);

Robert Gamble

Nov 15 '05 #3
In article <11**********************@z14g2000cwz.googlegroups .com>,
rg*******@gmail.com says...
Mike Wahler wrote:
"Radith" <ra****@xtra.co.nz> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi All,

I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:

"
You have been asked to write a program for a card playing friend. How
would you store information about playing cards? For example how would
you store the fact that a certain card is the 7 of diamonds? (You may
use more than one variable if you wish)
"

All help welcome.
Thanks in advance.

Radith


enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
enum faces {ACE = 1, JACK = 11, QUEEN, KING};

struct card
{
unsigned int rank;
unsigned char suit;
};

card c = {7, DIAMONDS};


struct card c = {7, DIAMONDS);

Robert Gamble

struct card c = {7, DIAMONDS};

If you're gonna be a nit-picky smart-ass, you better be correct.
Nov 15 '05 #4
On 9 Aug 2005 18:00:41 -0700, "Radith" <ra****@xtra.co.nz> wrote:
Hi All,

I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:

"
You have been asked to write a program for a card playing friend. How
would you store information about playing cards? For example how would
you store the fact that a certain card is the 7 of diamonds? (You may
use more than one variable if you wish)
"


You have lots of options. Just to start you off consider a struct
with two members or a 2D array of char.
<<Remove the del for email>>
Nov 15 '05 #5
John Doe wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
rg*******@gmail.com says...
Mike Wahler wrote:
"Radith" <ra****@xtra.co.nz> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
> Hi All,
>
> I have got this task which I cant get my head around:
> It asks how I would store information:
> I just want to get an opinion from the group:
> So here's the question:
>
> "
> You have been asked to write a program for a card playing friend. How
> would you store information about playing cards? For example how would
> you store the fact that a certain card is the 7 of diamonds? (You may
> use more than one variable if you wish)
> "
>
> All help welcome.
> Thanks in advance.
>
> Radith

enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
enum faces {ACE = 1, JACK = 11, QUEEN, KING};

struct card
{
unsigned int rank;
unsigned char suit;
};

card c = {7, DIAMONDS};


struct card c = {7, DIAMONDS);

Robert Gamble

struct card c = {7, DIAMONDS};


Obviously that was an attempt to keep true to the tradition that any
post correcting a grammatical (or syntactical) error must introduce one
of it's own ;)

Robert Gamble

Nov 15 '05 #6
In article <vv****************@newsread1.news.pas.earthlink.n et>,
Mike Wahler <mk******@mkwahler.net> wrote:
enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
enum faces {ACE = 1, JACK = 11, QUEEN, KING}; struct card
{
unsigned int rank;
unsigned char suit;
}; card c = {7, DIAMONDS};


Mike, is there any particular reason you used int for rank when
you only used char for suit? The minimum size for char has
enough range to cover the largest possible card rank, which would
tend to suggest something like using char for each of
the elements.
For that matter, if space is more important than efficiency, then

struct card
{
unsigned char rank: 5;
unsigned char suit: 3;
}

or perhaps
#define rank_of(card) (((card)&0x1e)>>1)
#define suit_of(card) (((card)&0xe1)>>5)
#define is_face_up(card) ((card)&1)
#define build_card(rank,suit,faceup) ((suit)<<5 | ((rank)<<1) | (faceup))

typedef unsigned char card;
Mind you, I wouldn't recommend this latter implementation to anyone who
doesn't understand why the symmetry of the bitmasks is important
in rank_of() and suit_of().
--
"This was a Golden Age, a time of high adventure, rich living and
hard dying... but nobody thought so." -- Alfred Bester, TSMD
Nov 15 '05 #7
"Robert Gamble" <rg*******@gmail.com> writes:
[...]
Obviously that was an attempt to keep true to the tradition that any
post correcting a grammatical (or syntactical) error must introduce one
of it's own ;)


Shouldn't that be "its'"?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #8
Walter Roberson wrote:
In article <vv****************@newsread1.news.pas.earthlink.n et>,
#define rank_of(card) (((card)&0x1e)>>1)
#define suit_of(card) (((card)&0xe1)>>5)
#define is_face_up(card) ((card)&1)
#define build_card(rank,suit,faceup) ((suit)<<5 | ((rank)<<1) | (faceup))

typedef unsigned char card;
Mind you, I wouldn't recommend this latter implementation to anyone who
doesn't understand why the symmetry of the bitmasks is important
in rank_of() and suit_of().


Ok, you wouldn't recommend this implementation to me, cause I can't see
why the symmetry of the two bitmasks is so important.

Correct me if I'm wrong, but

#define suit_of(card) (((card)&0xe0)>>5)

would produce exactly the same result in every situation.

Nov 15 '05 #9
Radith wrote:

Hi All,

I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:

"
You have been asked to write a program for a card playing friend. How
would you store information about playing cards? For example how would
you store the fact that a certain card is the 7 of diamonds? (You may
use more than one variable if you wish)


/* BEGIN shuffle.c */

#include <stdio.h>
#include <time.h>

#define LU_RAND_SEED 123456789LU
#define LU_RAND(S) ((S) * 69069 + 362437 & 0xffffffffLU)
#define SUITS (sizeof suit / sizeof *suit)
#define RANKS (sizeof rank / sizeof *rank)
#define CARDS (SUITS * RANKS)
#define HAND 5
#define DEALS 5

struct poker {
int suit;
int rank;
};

long unsigned shuffle(int *, int, long unsigned);
int compar_rank(void const*, void const*);
int compar_suit(void const*, void const*);
int straight(struct poker *);
int pair(struct poker *);
int flush(struct poker *);
int three(struct poker *);
int four(struct poker *);
int full(struct poker *);
int two_pair(struct poker *);
void s_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

int main(void)
{
size_t card;
struct poker hand[HAND];
long unsigned deal;
long unsigned seed = LU_RAND_SEED;
char *suit[] = {"Hearts","Diamonds","Clubs","Spades"};
char *rank[] = {"Deuce","Three","Four","Five","Six",
"Seven","Eight","Nine","Ten","Jack","Queen","King" ,"Ace"
};
int deck[CARDS];

putchar('\n');
/**/
seed = (long unsigned)time(0);
/*//**/
deal = DEALS;
while (deal-- != 0) {
seed = shuffle(deck, CARDS, seed);
for (card = 0; card != HAND; ++card) {
hand[card].suit = deck[card] % SUITS;
hand[card].rank = deck[card] % RANKS;
}
if (pair(hand)) {
if (three(hand)) {
if (four(hand)) {
puts("Four of a Kind:");
} else {
if (full(hand)) {
puts("Full House:");
} else {
puts("Three of a Kind:");
}
}
} else {
if (two_pair(hand)) {
puts("Two Pair:");
} else {
puts("Pair:");
}
}
} else {
switch (2 * flush(hand) + straight(hand)) {
case 0:
s_sort(hand, HAND, sizeof *hand, compar_rank);
printf("%s High:\n", rank[hand[4].rank]);
break;
case 1:
puts("Straight:");
break;
case 2:
puts("Flush:");
break;
default:
puts("Straight Flush:");
break;
}
}
putchar('\n');
for (card = 0; card != HAND; ++card) {
printf("%s of %s\n",
rank[deck[card] % RANKS],
suit[deck[card] % SUITS]);
}
putchar('\n');
}
return 0;
}

int pair(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_rank);
return hand[1].rank == hand[0].rank
|| hand[2].rank == hand[1].rank
|| hand[3].rank == hand[2].rank
|| hand[4].rank == hand[3].rank;
}

int three(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_rank);
return hand[0].rank == hand[2].rank
|| hand[1].rank == hand[3].rank
|| hand[2].rank == hand[4].rank;
}

int four(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_rank);
return hand[0].rank == hand[3].rank
|| hand[1].rank == hand[4].rank;
}

int full(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_rank);
return hand[1].rank == hand[0].rank
&& hand[4].rank == hand[3].rank
&&(hand[2].rank == hand[1].rank
|| hand[3].rank == hand[2].rank);
}

int two_pair(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_rank);
return hand[1].rank == hand[0].rank
&& hand[2].rank == hand[3].rank
|| hand[1].rank == hand[0].rank
&& hand[4].rank == hand[3].rank
|| hand[1].rank == hand[2].rank
&& hand[4].rank == hand[3].rank;
}

int straight(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_rank);
return hand[4].rank == hand[3].rank + 1
&& hand[3].rank == hand[2].rank + 1
&& hand[2].rank == hand[1].rank + 1
&&(hand[1].rank == hand[0].rank + 1
|| hand[1].rank == 0 && hand[0].rank == 12);
}

int flush(struct poker *hand)
{
s_sort(hand, HAND, sizeof *hand, compar_suit);
return hand[0].suit == hand[4].suit;
}

int compar_rank(void const *first, void const *second)
{
int int_1 = (*(struct poker*)first).rank;
int int_2 = (*(struct poker*)second).rank;

return int_2 > int_1 ? -1 : int_2 != int_1;
}

int compar_suit(void const *first, void const *second)
{
int int_1 = (*(struct poker*)first).suit;
int int_2 = (*(struct poker*)second).suit;

return int_2 > int_1 ? -1 : int_2 != int_1;
}

long unsigned shuffle(int *array, int n, long unsigned seed)
{
int i, r;

array[0] = 0;
for (i = 1; n > i; ++i) {
seed = LU_RAND(seed);
r = seed % (i + 1);
array[i] = 0;
array[i] = array[r];
array[r] = i;
}
return seed;
}

void s_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
size_t bytes;
unsigned char *array, *after, *i, *j, *k, *p1, *p2, *end, swap;

array = base;
after = nmemb * size + array;
if (nmemb > (size_t)-1 / 3 - 1) {
nmemb = nmemb / 3 - 1;
} else {
nmemb = (nmemb * 3 + 1) / 7;
}
while (nmemb != 0) {
bytes = nmemb * size;
i = bytes + array;
do {
j = i - bytes;
if (compar(j, i) > 0) {
k = i;
do {
p1 = j;
p2 = k;
end = p2 + size;
do {
swap = *p1;
*p1++ = *p2;
*p2++ = swap;
} while (p2 != end);
if (bytes + array > j) {
break;
}
k = j;
j -= bytes;
} while (compar(j, k) > 0);
}
i += size;
} while (i != after);
nmemb = (nmemb * 3 + 1) / 7;
}
}

/* END shuffle.c */
--
pete
Nov 15 '05 #10
Walter Roberson wrote:
#define rank_of(card) (((card)&0x1e)>>1)
#define suit_of(card) (((card)&0xe1)>>5)
#define is_face_up(card) ((card)&1)
#define build_card(rank,suit,faceup) ((suit)<<5 | ((rank)<<1) | (faceup))

typedef unsigned char card;
Mind you, I wouldn't recommend this latter implementation to anyone who
doesn't understand why the symmetry of the bitmasks is important
in rank_of() and suit_of().


I'll bite -- what advantage would there be to having the symmetrical bit
masks?

Thad

Nov 15 '05 #11
On Wed, 10 Aug 2005 10:07:48 +0000, pete wrote:
/* BEGIN shuffle.c */ <snip poker hand source code> /* END shuffle.c */


Neat pete. Yours? Used in?

--
http://members.dodo.com.au/~netocrat

Nov 15 '05 #12

"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Mike Wahler wrote:
struct card
{
unsigned int rank;
unsigned char suit;
};

card c = {7, DIAMONDS};


struct card c = {7, DIAMONDS);


Oops, my C++ is showing. :-)

Thanks for the correction.

-Mike
Nov 15 '05 #13

"John Doe" <na**@domain.com> wrote in message
news:MP************************@news-server.mn.rr.com...
In article <11**********************@z14g2000cwz.googlegroups .com>,
rg*******@gmail.com says...
Mike Wahler wrote:
> "Radith" <ra****@xtra.co.nz> wrote in message
> news:11*********************@g49g2000cwa.googlegro ups.com...
> > Hi All,
> >
> > I have got this task which I cant get my head around:
> > It asks how I would store information:
> > I just want to get an opinion from the group:
> > So here's the question:
> >
> > "
> > You have been asked to write a program for a card playing friend. How
> > would you store information about playing cards? For example how
> > would
> > you store the fact that a certain card is the 7 of diamonds? (You may
> > use more than one variable if you wish)
> > "
> >
> > All help welcome.
> > Thanks in advance.
> >
> > Radith
>
> enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
> enum faces {ACE = 1, JACK = 11, QUEEN, KING};
>
> struct card
> {
> unsigned int rank;
> unsigned char suit;
> };
>
> card c = {7, DIAMONDS};


struct card c = {7, DIAMONDS);

Robert Gamble

struct card c = {7, DIAMONDS};

If you're gonna be a nit-picky smart-ass, you better be correct.


Well, that was my error (see my original post).
I suspect Robert just copy-pasted and inserted
the 'struct' keyword. But imo he got the message
across.

-Mike
Nov 15 '05 #14

"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
John Doe wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
rg*******@gmail.com says...
> Mike Wahler wrote:
> > "Radith" <ra****@xtra.co.nz> wrote in message
> > news:11*********************@g49g2000cwa.googlegro ups.com...
> > > Hi All,
> > >
> > > I have got this task which I cant get my head around:
> > > It asks how I would store information:
> > > I just want to get an opinion from the group:
> > > So here's the question:
> > >
> > > "
> > > You have been asked to write a program for a card playing friend.
> > > How
> > > would you store information about playing cards? For example how
> > > would
> > > you store the fact that a certain card is the 7 of diamonds? (You
> > > may
> > > use more than one variable if you wish)
> > > "
> > >
> > > All help welcome.
> > > Thanks in advance.
> > >
> > > Radith
> >
> > enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
> > enum faces {ACE = 1, JACK = 11, QUEEN, KING};
> >
> > struct card
> > {
> > unsigned int rank;
> > unsigned char suit;
> > };
> >
> > card c = {7, DIAMONDS};
>
> struct card c = {7, DIAMONDS);
>
> Robert Gamble
>
>

struct card c = {7, DIAMONDS};


Obviously that was an attempt to keep true to the tradition that any
post correcting a grammatical (or syntactical) error must introduce one
of it's own ;)


But it didn't. It was there already. However your post
does have a punctuation error. :-)

-Mike
Nov 15 '05 #15

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:dd**********@canopus.cc.umanitoba.ca...
In article <vv****************@newsread1.news.pas.earthlink.n et>,
Mike Wahler <mk******@mkwahler.net> wrote:
enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
enum faces {ACE = 1, JACK = 11, QUEEN, KING};
struct card
{
unsigned int rank;
unsigned char suit;
};

card c = {7, DIAMONDS};


Mike, is there any particular reason you used int for rank
you only used char for suit?


Midcourse design change. :-) I originally was going to
use characters (e.g. 'C', 'H', 'D', 'S') for the suit,
but then went with the enum. Didn't even think to change
the type.
The minimum size for char has
enough range to cover the largest possible card rank, which would
tend to suggest something like using char for each of
the elements.
Right.


For that matter, if space is more important than efficiency, then


I wasn't concerned with 'efficiency' of any sort, only
demonstrating a data structure

-Mike
Nov 15 '05 #16
Mike Wahler wrote:
"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
John Doe wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
rg*******@gmail.com says...
> Mike Wahler wrote:
> > "Radith" <ra****@xtra.co.nz> wrote in message
> > news:11*********************@g49g2000cwa.googlegro ups.com...
> > > Hi All,
> > >
> > > I have got this task which I cant get my head around:
> > > It asks how I would store information:
> > > I just want to get an opinion from the group:
> > > So here's the question:
> > >
> > > "
> > > You have been asked to write a program for a card playing friend.
> > > How
> > > would you store information about playing cards? For example how
> > > would
> > > you store the fact that a certain card is the 7 of diamonds? (You
> > > may
> > > use more than one variable if you wish)
> > > "
> > >
> > > All help welcome.
> > > Thanks in advance.
> > >
> > > Radith
> >
> > enum suits {CLUBS, HEARTS, DIAMONDS, SPADES};
> > enum faces {ACE = 1, JACK = 11, QUEEN, KING};
> >
> > struct card
> > {
> > unsigned int rank;
> > unsigned char suit;
> > };
> >
> > card c = {7, DIAMONDS};
>
> struct card c = {7, DIAMONDS);
>
> Robert Gamble
>
>
struct card c = {7, DIAMONDS};
Obviously that was an attempt to keep true to the tradition that any
post correcting a grammatical (or syntactical) error must introduce one
of it's own ;)


But it didn't. It was there already.


Your original post had a closed-curly bracket, not a parenthesis.
However your post does have a punctuation error. :-)


The emoticon is serving as puncutation, the grammatical error was the
fact that "it's" should have been "its". Keith pointed this out but
his correction, in keeping with tradition I'm sure, was incorrect.

Robert Gamble

Nov 15 '05 #17

"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Mike Wahler wrote:
> Obviously that was an attempt to keep true to the tradition that any
> post correcting a grammatical (or syntactical) error must introduce one
> of it's own ;)


But it didn't. It was there already.


Your original post had a closed-curly bracket, not a parenthesis.


Sorry, my mistake.
However your post does have a punctuation error. :-)
The emoticon is serving as puncutation, the grammatical error was the
fact that "it's" should have been "its".


You're calling that a grammatical error, I called it
a punctuation error.
Keith pointed this out but
his correction, in keeping with tradition I'm sure, was incorrect.


His correction of your incorrect use of "it's" was correct. The
apostrophe is only used with "'it" to form the contraction for
"it is". The possessive does not use the apostrophe.

-Mike
Nov 15 '05 #18

Mike Wahler wrote:
"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Mike Wahler wrote:

> Obviously that was an attempt to keep true to the tradition that any
> post correcting a grammatical (or syntactical) error must introduce one
> of it's own ;)

But it didn't. It was there already.


Your original post had a closed-curly bracket, not a parenthesis.


Sorry, my mistake.
However your post does have a punctuation error. :-)


The emoticon is serving as puncutation, the grammatical error was the
fact that "it's" should have been "its".


You're calling that a grammatical error, I called it
a punctuation error.
Keith pointed this out but
his correction, in keeping with tradition I'm sure, was incorrect.


His correction of your incorrect use of "it's" was correct. The
apostrophe is only used with "'it" to form the contraction for
"it is". The possessive does not use the apostrophe.

Precisely. Keith answer was:

Shouldn't that be "its'"?

Can't you see the little apostrophe after "its"? That single character
makes his answer incorrect. :P

Nov 15 '05 #19
Mike Wahler wrote:
Robert Gamble wrote:
Mike Wahler wrote:

Obviously that was an attempt to keep true to the tradition that any
post correcting a grammatical (or syntactical) error must introduce one
of it's own ;)

However your post does have a punctuation error. :-)


The emoticon is serving as puncutation, the grammatical error was the
fact that "it's" should have been "its".


You're calling that a grammatical error, I called it
a punctuation error.
Keith pointed this out but
his correction, in keeping with tradition I'm sure, was incorrect.


His correction of your incorrect use of "it's" was correct. The
apostrophe is only used with "'it" to form the contraction for
"it is". The possessive does not use the apostrophe.


Your correction of his Robert's observation of Keith's correction
of Robert's incorrect usage seems to be incorrect. :)

Keith wrote that it should be " its' " (note the trailing
apostrophe), which is incorrect (not correct, as you said).
However you correctly pointed out that the possessive of "it"
does not use an apostrophe at all. In fact it is the
only English word that has this property.

Nov 15 '05 #20
Old Wolf wrote:

Keith wrote that it should be " its' " (note the trailing
apostrophe), which is incorrect (not correct, as you said).
However you correctly pointed out that the possessive of "it"
does not use an apostrophe at all. In fact it is the
only English word that has this property.


Also "his" and "hers".

Brian
Nov 15 '05 #21
"Old Wolf" <ol*****@inspire.net.nz> writes:
Mike Wahler wrote:
Robert Gamble wrote:
Mike Wahler wrote:
> Obviously that was an attempt to keep true to the tradition that any
> post correcting a grammatical (or syntactical) error must introduce one
> of it's own ;)

However your post does have a punctuation error. :-)

The emoticon is serving as puncutation, the grammatical error was the
fact that "it's" should have been "its".


You're calling that a grammatical error, I called it
a punctuation error.
> Keith pointed this out but
> his correction, in keeping with tradition I'm sure, was incorrect.


His correction of your incorrect use of "it's" was correct. The
apostrophe is only used with "'it" to form the contraction for
"it is". The possessive does not use the apostrophe.


Your correction of his Robert's observation of Keith's correction
of Robert's incorrect usage seems to be incorrect. :)

Keith wrote that it should be " its' " (note the trailing
apostrophe), which is incorrect (not correct, as you said).


Which was precisely my intent.
However you correctly pointed out that the possessive of "it"
does not use an apostrophe at all. In fact it is the
only English word that has this property.


No, it's one of several, and it's part of a consistent pattern.
Possessives of pronouns in general do not take apostrophes (he -->
his, she/her --> her/hers, you --> your/yours, we/us --> our/ours, it
--> its). Contractions involving pronouns do take apostrophes (he is
--> he's, she is --> she's, you are --> you're, we are --> we're, it
is --> it's). The spellings are irregular, but the apostrophe rules
are consistent.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #22

"Antonio Contreras" <an*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Mike Wahler wrote:
His correction of your incorrect use of "it's" was correct. The
apostrophe is only used with "'it" to form the contraction for
"it is". The possessive does not use the apostrophe.

Precisely. Keith answer was:

Shouldn't that be "its'"?

Can't you see the little apostrophe after "its"?


Now I do. I didn't notice it before, I was too focused on
the one Robert used incorrectly.
That single character
makes his answer incorrect. :P


That's correct. It's incorrect. :-)

-Mike
Nov 15 '05 #23
Netocrat wrote:

On Wed, 10 Aug 2005 10:07:48 +0000, pete wrote:
/* BEGIN shuffle.c */ <snip poker hand source code>
/* END shuffle.c */


Neat pete.


I'm glad that you like it.
Paul Hsieh posted one in comp.programming a while ago,
that scored the poker hands.
Yours?
Yes.
It has a few algorithms that I picked up here and other places.
Used in?


I just like to post code a lot.

--
pete
Nov 15 '05 #24
pete wrote:
Paul Hsieh posted one in comp.programming a while ago,
that scored the poker hands.


He posted a URL.

http://www.pobox.com/~qed/poker.zip

--
pete
Nov 15 '05 #25
Antonio Contreras wrote:
Walter Roberson wrote:
In article <vv****************@newsread1.news.pas.earthlink.n et>,
#define rank_of(card) (((card)&0x1e)>>1)
#define suit_of(card) (((card)&0xe1)>>5)
#define is_face_up(card) ((card)&1)
#define build_card(rank,suit,faceup) ((suit)<<5 | ((rank)<<1) | (faceup))

typedef unsigned char card;
Mind you, I wouldn't recommend this latter implementation to anyone who
doesn't understand why the symmetry of the bitmasks is important
in rank_of() and suit_of().


Correct me if I'm wrong, but

#define suit_of(card) (((card)&0xe0)>>5)

would produce exactly the same result in every situation.


As would
#define suit_of(card) ((card)>>5)

since card is the most-significant field.

Thad

Nov 15 '05 #26
In article <42***********************@auth.newsreader.octanew s.com>,
Thad Smith <Th*******@acm.org> wrote:
Antonio Contreras wrote:
Walter Roberson wrote:
#define suit_of(card) (((card)&0xe1)>>5)
Correct me if I'm wrong, but
#define suit_of(card) (((card)&0xe0)>>5)
would produce exactly the same result in every situation.

As would
#define suit_of(card) ((card)>>5) since card is the most-significant field.


Thad, make that "The most significant field that is populated in
that code snippet." Other code might fiddle with higher-order bits
(e.g., to mark the card as discarded.) (Not portably, but it
could happen if CHAR_BIT > 8.) When working with bits, it is
a safer design to treat each grouping independantly, as if there might
be additional used bits before or afterward.
--
"Who Leads?" / "The men who must... driven men, compelled men."
"Freak men."
"You're all freaks, sir. But you always have been freaks.
Life is a freak. That's its hope and glory." -- Alfred Bester, TSMD
Nov 15 '05 #27

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an...
2
by: kelvSYC | last post by:
I'm trying to program something along the lines of a "trading card" idea: I have a single copy of the "card" in the program, yet there may be multiple "instances" of the "card", with differing...
5
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing...
9
by: elyob | last post by:
Hi, I'm looking at storing snippets of details in MySQL about what credit cards a business excepts. Rather than have a whole column for Visa, another for Amex etc ... I am looking at having a...
6
by: Kieran Benton | last post by:
Hi, I have quite a lot of metadata in a WinForms app that I'm currently storing within a hashtable, which is fine as long as I know the unique ID of the track (Im storing info on media files). Up...
12
by: Alex D. | last post by:
is it possible? pros and cons?
10
by: Arun Nair | last post by:
Can any one help me with this im not getting it even after reading books because there is not much of discussion anywhere a> Implement a calss that represents a playing card. The class should...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
8
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.