数据文件——之从键盘设备文件中读取

代码:

复制代码
 1 //This is c program code!
 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_21.c
 4   * 版权声明: *** :(魎魍魅魑)MIT
 5   * 联络信箱: *** :guochaoxxl@163.com
 6   * 创建时间: *** :2020年11月22日的下午02:05
 7   * 文档用途: *** :数据结构与算法分析-c语言描述
 8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
 9   * 修订时间: *** :2020年第46周 11月22日 星期日 下午02:05 (第327天)
10   * 文件描述: *** :自行添加
11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
12 #include <stdio.h>
13 
14 #define SIZE 500
15     
16 int main(int argc, char **argv)
17 {       
18     char text[SIZE];
19     puts("Type the text. The text you type form the contents: ");
20     puts("of the device-file keyboard. Strike the function");
21     puts("ke F6 to signify the end of this file.");
22 
23     int size = 0;
24     int ch = fgetc(stdin);                                                                                          
25     while(ch != EOF){
26         text[size] = ch;
27         size = size + 1;
28         ch = fgetc(stdin);
29     }   
30         
31     puts("Contents of device file \"keyboard\":");
32     for(int i = 0; i < size; i++){
33         putchar(text[i]);
34     }   
35         
36     return 0;
37 }
复制代码

 

posted @   叕叒双又  阅读(119)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示