飞鱼的成长

 

因本人不再做技术,

这个blog将不再连载技术文章,

只作为心情点滴的记录,

想学技术的请绕道,谢谢!

联系方式:

feiyu_lili@163.com


时 间 记 忆
«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31

最 新 评 论
回复:什么都是错,唯有行动才是真道理
回复:我有个梦想
回复:自动词和他动词的分类比较[转][小
回复:Binaryluo 的  [网络编
回复:如何实现人生价值(转)
回复:工作有感
回复:如何实现人生价值(转)
回复:如何实现人生价值(转)
回复:如何实现人生价值(转)
回复:我有个梦想

最 新 日 志
我有个梦想
工作有感
我的人生路该怎么走
什么都是错,唯有行动才是真道理
想家的孩子
解压的方法(转)
关于我的一些调节心态的方法(转)
具体应该怎样同懒惰性做斗争?(转)
如何实现人生价值(转)
希望这里的房子能早点租掉

最 新 留 言
签写新留言

日语自动,他动
化妆了 :)
步伐当然记得你啦(不能回复,只能另起炉灶
好久不见了。。。
睡觉的问题
………………
~~~~~
。。。。
还以为你去日本了来
那里去了???

搜 索


用 户 登 录
用户名称:
登陆密码:
密码保存:

友 情 连 接

凡弟のBlog

祺弟のBlog

臭釉のBlog

 

blog名称:飞鱼的成长
日志总数:120
评论数量:488
留言数量:18
访问次数:1047671
建立时间:2006年2月27日
 
 
 
[c语言]函数中的多源代码文件程序的编译[C primer plus读书笔记]
[ 2006/3/16 9:25:22 | By: feiyu_lili ]
 
今天基本看完了函数这章,今天印象最深的是多源代码的文件程序编译。以前虽然也有分模块的概念但都是写在同一个文件内的。这次学会多文件的模块化。还有一个就是把宏定义单独的放在一个.h文件里面。   多源代码文件程序的编译 usehotel.c  控制模块 /* usehotel.c -- room rate program */ /* compile with  Listing 9.10      */ #include <stdio.h> #include "hotel.h" /* defines constants, declares functions */   int main(void) {    int nights;    double hotel_rate;    int code;      while ((code = menu()) != QUIT)    {       switch(code)       {       case 1 : hotel_rate = HOTEL1;                break;       case 2 : hotel_rate = HOTEL2;                break;       case 3 : hotel_rate = HOTEL3;                break;       case 4 : hotel_rate = HOTEL4;                break;       default: hotel_rate = 0.0;                printf("Oops!\n");                break;       }       nights = getnights();       showprice(hotel_rate, nights);    }    printf("Thank you and goodbye.");       return 0; } hotel.c函数支持模块 *************************************************** /* hotel.c -- hotel management functions */ #include <stdio.h> #include "hotel.h" int menu(void) {     int code, status;       printf("\n%s%s\n", STARS, STARS);     printf("Enter the number of the desired hotel:\n");     printf("1) Fairfield Arms           2) Hotel Olympic\n");     printf("3) Chertworthy Plaza        4) The Stockton\n");     printf("5) quit\n");     printf("%s%s\n", STARS, STARS);     while ((status = scanf("%d", &code)) != 1  ||              (code < 1 || code > 5))    {         if (status != 1)             scanf("%*s");   //跳至下一个空白字符         printf("Enter an integer from 1 to 5, please.\n");     }        return code; }   int getnights(void) {     int nights;       printf("How many nights are needed? ");     while (scanf("%d", &nights) != 1)     {         scanf("%*s");         printf("Please enter an integer, such as 2.\n");     }        return nights; }   void showprice(double rate, int nights) {     int n;     double total = 0.0;     double factor = 1.0;       for (n = 1; n <= nights; n++, factor *= DISCOUNT)         total += rate * factor;     printf("The total cost will be $%0.2f.\n", total); } hotel.h头文件 ***************************************************** /* hotel.h -- constants and declarations for hotel.c */ #define QUIT       5 #define HOTEL1    80.00 #define HOTEL2   125.00 #define HOTEL3   155.00 #define HOTEL4   200.00 #define DISCOUNT   0.95 #define STARS "**********************************"   // shows list of choices int menu(void);   // returns number of nights desired int getnights(void);   // calculates price from rate, nights // and displays result void showprice(double rate, int nights); 500)this.width=500'>  
 

阅读全文(2941) | 回复(0) | 编辑 | 精华
 

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
 
站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.030 second(s), page refreshed 144760377 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号