- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Copyrightamp;copy;2008W.W.Nortonamp;amp;Company.Allrightsreserved..ppt
Program:给一手牌分类 read_cards函数 和analyze_hand 函数都需要访问数组num_in_rank 和num_in_suit ,所以这两个数组必须是外部变量. 数组 card_exists 只用于read_cards函数,所以可将它设为此函数的局部变量. 通常只有在必要时才把变量设置为外部变量. Copyright ? 2008 W. W. Norton Company. All rights reserved. * poker.c ? /* Classifies a poker hand */ ? #include stdbool.h /* C99 only */ #include stdio.h #include stdlib.h ? #define NUM_RANKS 13 #define NUM_SUITS 4 #define NUM_CARDS 5 /* external variables */ int num_in_rank[NUM_RANKS]; int num_in_suit[NUM_SUITS]; bool straight, flush, four, three; int pairs; /* can be 0, 1, or 2 */ Copyright ? 2008 W. W. Norton Company. All rights reserved. * /* prototypes */ void read_cards(void); void analyze_hand(void); void print_result(void); ? /********************************************************** * main: Calls read_cards, analyze_hand, and print_result * * repeatedly. * **********************************************************/ int main(void) { for (;;) { read_cards(); analyze_hand(); print_result(); } } Copyright ? 2008 W. W. Norton Company. All rights reserved. * /********************************************************** * read_cards: Reads the cards into the external * * variables num_in_rank and num_in_suit; * * checks for bad cards and duplicate cards. * **********************************************************/ void read_cards(void) { bool card_exists[NUM_RANKS][NUM_SUITS]; char ch, rank_ch, suit_ch; int rank, suit; bool bad_card; int cards_read = 0; ? for (rank = 0; rank NUM_RANKS; rank++) { num_in_rank[rank] = 0; for (suit = 0; suit NUM_SUITS; suit++) card_exists[rank][suit] = false; } ? for (suit = 0; suit NUM_SUITS; suit++) num_in_suit[suit] = 0; Copyright ? 2008 W. W. Norton Company. All rights reserved. * while (cards_read NUM_CARDS) { bad_card = false; ? printf(Enter a card: ); ? rank_ch = getchar(); switch (rank_ch) {
您可能关注的文档
- Ch4. 目标成本与价格制定.ppt
- Challenges for education with equity.ppt
- Chapter 13 – Aggregate Planning.ppt
- Chapter 13 –Designing for Quality.ppt
- Chapter 13 - Inheritance and Polymorphism.ppt
- Chapter 13 - Introduction to Phylum Platyhelminthes.ppt
- Chapter 13 - The Preprocessor.ppt
- Chapter 13 16- Bit MS-DOS Programming.ppt
- Chapter 13 Accounting for Inflation & Changing Prices.ppt
- Chapter 13 Configuration Management.ppt
- CORPORATE GOVERNANCE.ppt
- COSOSIMO Workshop Outbrief14 March 2006.ppt
- CPEEE 428, CPE 528 Session #13.ppt
- CPSC 614 Computer Architecture Lec 18 – Storage.ppt
- Creative Problem SolvingChapter 13.ppt
- Cryptography and Network SecurityChapter 16.ppt
- CS155a E-Commerce.ppt
- CS510 Concurrent Systems Class 13.ppt
- CS533 Concepts of Operating SystemsClass 14.ppt
- CSE 160 – Lecture 16.ppt
文档评论(0)