Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1746841
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: C/C++

2015-04-30 12:46:34


点击(此处)折叠或打开

  1. #include <stdio.h>

  2. enum response_type {DUMP, SECOND_CHANCE, MARRIAGE};
  3. typedef struct {
  4.     char *name;
  5.     enum response_type type;
  6. } response;

  7. void dump(response r)
  8. {
  9.     printf("Dear %s,\n", r.name);
  10.     puts("Unfortunately your last date contacted us to");
  11.     puts("say that they will not be seeing you again");
  12. }
  13. void second_chance(response r)
  14. {
  15.     printf("Dear %s,\n", r.name);
  16.     puts("Good news: your last date has asked us to");
  17.     puts("arrange another meeting. Please call ASAP.");
  18. }
  19. void marriage(response r)
  20. {
  21.     printf("Dear %s,\n", r.name);
  22.     puts("Congratulations! Your last date has contacted");
  23.     puts("us with a proposal of marriage.");
  24. }

  25. void (*replies[])(response) = {dump, second_chance, marriage};

  26. int main()
  27. {
  28.     response r[] = {
  29.         {"Mike", DUMP}, {"Luis", SECOND_CHANCE},
  30.         {"Matt", SECOND_CHANCE}, {"William", MARRIAGE}
  31.     };
  32.     int i;
  33.     for (i = 0; i < 4; i++) {
  34.         (replies[r[i].type])(r[i]);
  35.         }

  36.     return 0;
  37. }

阅读(1380) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~