c struct, objective code

////////
////
typedef int (*PF_EAT) (char* food, const int cnt);
typedef int (*PF_WALK) (char* place, const int miles, int walk_miles);
typedef void (*PF_SAY) (const char* to_who, const char* words); #define FEMALE 0
#define MALE 1 typedef struct{
char* name;
char sex;
int age;
PF_EAT eat;
PF_WALK walk;
PF_SAY say;
}ST_PERSON; struct foods{
char name[];
int cnt;
}; struct foods food_to_full[] = {
{"milk", },
{"rice", },
{"bread", }
}; int f_eat (char* food, const int cnt)
{ int index = ;
int ret = -;//ret = -1, nothing to eat if(food == ){
return -;
} for(index = ; index < ; index++){
if(strcmp(food, food_to_full[index].name) == ){
ret = (cnt >= food_to_full[index].cnt ? : );//ret = 1, not full printf("eat %d *%s %s\n", cnt, food, ret == ? "is full" : "is not full"); break;
}
} return ret;
} int f_walk(char* place, const int miles, int walk_miles)
{
int ret = ;
if(place == ){
return ;
} ret = (miles - walk_miles > ) ? (miles - walk_miles) : ; printf("walk to %s, %s", place, ret > ? "is on the load" : "has arrived the location" ); if(ret > )
{
printf(", remains %d miles to walk", ret);
}
printf("\n");
return ret; } void f_say (const char* to_who, const char* words)
{
printf("Hi %s, %s\n",to_who, words);
} void person_one_day(ST_PERSON *person, struct foods* food_have, char *where, int miles, int walk_miles, char* to_who, char* words )
{
printf("%s, %s, %d years old\n", person->name, (person->sex == MALE) ? "male" : "female", person->age);
person->eat(food_have->name, food_have->cnt);
person->walk(where, miles, walk_miles);
person->say(to_who , words); printf("\n");
}
ST_PERSON Ocean = {
.name = "Ocean",
.sex = MALE,
.age = ,
.eat = f_eat,
.walk = f_walk,
.say = f_say,
}; ST_PERSON Li = {
.name = "Li",
.sex = FEMALE,
.age = ,
.eat = f_eat,
.walk = f_walk,
.say = f_say,
};
int main(int argc, char** argv) 
{
struct foods food_have_ocean = {"rice", };
struct foods food_have_li = {"milk", };
person_one_day(&Li, &food_have_li, "town", , , "Lucy", "I am so tired!");
person_one_day(&Ocean, &food_have_ocean, "town", , , "Lucy", "I am waiting for my wife");
return ;
}

/*

>gcc person.c ; ./a.out

Li, female, 28 years old
eat 1 *milk is not full
walk to town, is on the load, remains 4 miles to walk
Hi Lucy, I am so tired!


Ocean, male, 26 years old
eat 1 *rice is full
walk to town, has arrived the location
Hi Lucy, I am waiting for my wife

*/

c语言, objective code(new 1)的更多相关文章

  1. c语言, objective code(new 2)

    参考: 1. C中的继承和多态 http://www.cnblogs.com/skynet/archive/2010/09/23/1833217.html

  2. C语言工具---Code::Blocks

    Code::Blocks Code::Blocks 是一个开源的全功能的跨平台C/C++集成开发环境. Code::Blocks是开放源码软件.由纯粹的C++语言开发完成,它使用了著名的图形界面库wx ...

  3. iOS开发核心语言Objective C —— 全部知识点总结

    本分享是面向有意向从事iOS开发的伙伴及苹果产品的发烧友,亦或是已经从事了iOS的开发人员,想进一步提升者.假设您对iOS开发有极高的兴趣,能够与我一起探讨iOS开发.一起学习,共同进步.假设您是零基 ...

  4. iOS开发核心语言Objective C —— 面向对象思维、setter和getter方法及点语法

    本分享是面向有意向从事iOS开发的伙伴们.或者已经从事了iOS的开发人员.假设您对iOS开发有极高的兴趣,能够与我一起探讨iOS开发.一起学习,共同进步.假设您是零基础,建议您先翻阅我之前分享的iOS ...

  5. iOS开发核心语言Objective C —— 所有知识点总结

    C和OC对比 OC中主要开发在什么平台上的应用程序?答:可以使用OC开发Mac OS X平台和iOS平台的应用程序 OC中新增关键字大部分是以什么开头?答:OC中新增关键字大部分是以@开头 OC中新增 ...

  6. 【转载】谷歌酝酿将苹果Swift作为安卓APP主要开发语言

    TNW中文站 4月8日报道 安卓操作系统的软件开发语言是Java,而在过去几年中,有关Java的版权,谷歌(微博)和甲骨文之间发生了长期的诉讼.最新外媒消息称,谷歌正在考虑将苹果开发的Swift作为未 ...

  7. Protobuf语言指南(转)

    Protobuf语言指南 l  定义一个消息(message)类型 l  标量值类型 l  Optional 的字段及默认值 l  枚举 l  使用其他消息类型 l  嵌套类型 l  更新一个消息类型 ...

  8. Protobuf语言指南

    Protobuf语言指南 l  定义一个消息(message)类型 l  标量值类型 l  Optional 的字段及默认值 l  枚举 l  使用其他消息类型 l  嵌套类型 l  更新一个消息类型 ...

  9. 【编辑器】Visual Studio Code

    1.官网:https://code.visualstudio.com/Download 2.插件:https://marketplace.visualstudio.com/VSCode https:/ ...

随机推荐

  1. Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connectio (andriod sdk manager) http://dl-ssl.google.com/android上不去解决方案

    Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml  Fetched Add-ons List succes ...

  2. 大神的vim配置

    大神的vim配置,O(∩_∩)O spf13-vim : Steve Francia's Vim Distribution __ _ _____ _ ___ _ __ / _/ |___ / __ _ ...

  3. hdu 3625 第一类striling 数

    /** 第一类Stirling数是有正负的,其绝对值是包含n个元素的集合分作k个环排列的方法数目. 递推公式为, S(n,0) = 0, S(1,1) = 1. S(n+1,k) = S(n,k-1) ...

  4. Application和Session的例子

    %@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationTest.as ...

  5. Web Deploy发布网站一条龙解决方案

    Web Deploy工具对于ASP.NET开发人员来说一定不陌生,没有用过也经常见到,Web Deploy发布十分方便而且在发布时会帮助用户检验发布文件的正确性.接下来介绍一下基础使用. 第一步:安装 ...

  6. C#_会员管理系统:开发六(数据搜索)

    增加界面中的搜索功能 会员资料管理界面(VIPManager.cs): 详细代码如下: using System; using System.Collections.Generic; using Sy ...

  7. 关于int.TryParse的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. c.Tom and paper

    Tom and paper Description There is a piece of paper in front of Tom, its length and width are intege ...

  9. Android中EditText,Button等控件的设置

    EditText可以使用:TextView.setEnabled(true)来设置为可编辑,其实很简单,写在这里以便以后自己查看. Button设置可用性:setVisibility(View.VIS ...

  10. Firemonkey ListBoxItem自绘

    ListBoxItem1的事件ListBoxItem1Paint procedure TForm1.ListBoxItem1Paint(Sender: TObject; Canvas: TCanvas ...