Example #1
0
int main(int argc, char *argv)
{	
	to16 v16_orig, v16_turn1,v16_turn2;	/*一个to16类型变量*/
	to32 v32_orig, v32_turn1,v32_turn2; /*一个to32类型变量*/
	
	
	v16_orig.value = 0xabcd;		/* 赋值为0xabcd */
	v16_turn1.value = htons(v16_orig.value);/*第一次转换*/
	v16_turn2.value = ntohs(v16_turn1.value);/*第二次转换*/
	
	v32_orig.value = 0x12345678;	/* 赋值为0x12345678 */
	v32_turn1.value = htonl(v32_orig.value);/*第一次转换*/
	v32_turn2.value = ntohl(v32_turn1.value);/*第二次转换*/
	
	/* 打印结果 */
	printf("16 host to network byte order change:\n");	
	printf("\torig:\t");showvalue(v16_orig.byte, BITS16);	/* 16位数值的原始值 */
	printf("\t1 times:");showvalue(v16_turn1.byte, BITS16); /* 16位数值的第一次转换后的值 */
	printf("\t2 times:");showvalue(v16_turn2.byte, BITS16); /* 16位数值的第二次转换后的值 */
	
	printf("32 host to network byte order change:\n");
	printf("\torig:\t");showvalue(v32_orig.byte, BITS32);   /* 32位数值的原始值 */
	printf("\t1 times:");showvalue(v32_turn1.byte, BITS32); /* 32位数值的第一次转换后的值 */
	printf("\t2 times:");showvalue(v32_turn2.byte, BITS32); /* 32位数值的第二次转换后的值 */
	
	
	return 0;	
}
Example #2
0
int
hit (hand *h) {
    card c = draw();
    printf("%s\n", card_name(c));
    add(h, c);
    showvalue(h, 1);
    if (busted(h)) {
        printf("[BUST]\n");
        return 0;
    } else {
        return handvalue(h);
    }
}
Example #3
0
void
show (hand *h, int reveal) {
    card *c;
    if (clist_length(h->cards) == 0) {
        printf("[no cards]\n");
        return;
    } else {
        if (reveal) {
            printf(" %s\n", card_name(*h->cards.first));
        } else {
            printf(" one face down card\n");
        }
    }
    for (c=h->cards.first->next; c!=NULL; c=c->next)
        printf(" %s\n", card_name(*c));

    showvalue(h, reveal);
    if (h->bet > 0)
        printf ("Bet: $%0.2f\n", h->bet);
}