当前位置:网站首页>Linuix cat instruction
Linuix cat instruction
2022-04-22 00:32:00 【Ten years moo sword】
Catalog
Preface
I told you before fputc Not at all Line cache It was used while(1); And join newline validation
fputc and fgetc Configuration and use Note that the cursor should be shifted back to the 0 A place
This section talks about cat The principle of instruction
cat Instruction Introduction
cat Implementation process

take a.C analogy
The user reads from the kernel first The user is writing to the kernel Through the driver of the kernel Output to the display
getc/fputc Function coordination Realization cat Instructions
use man Shape parameter Just make it happen
I learned from the front 1 gets/puts 2 fgets/fputs 3 fgetc/fputc Three groups of Read and write functions
1 You can't Because it can only be simple Output Input
int argc: Indicates the number of parameters on the command line
char *argv[]: The actual parameters are determined by the system when entering the command line A total of three.
Now? cat Count one Don't write it in code argv[0]
because The first is the fixed instruction The latter two are the source file names Or parameters

#include<stdio.h>
int main(int argc,char *argv[])
{
FILE *fd;
int str;
if(argc!=2)// If it's not two parameters It's the exception cat xxx.C It's just two parameters
{
printf("fopen is error\n");
return -1;
}
printf("fopen is success\n");
fd=fopen(argv[1],"r");
while(1) // Because I read and write more than once So just loop
{
Nret=fgetc(fd);
if(feof(Nret))// Read to the end of the file and exit
{
break;
}
fputc(Nret,stdout);// Output to the display
}
flcose(fd);
return 0;
}
see Source file

see Other documents

Both files can be viewed It proved successful
版权声明
本文为[Ten years moo sword]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220024494221.html
边栏推荐
- 容器雲系列之容器技術相關概念介紹
- Multiple forms of alternate printing implemented by multithreading
- Cocoscreator learning sample collection v3 four point two
- When the notebook expands the external display, the mouse cannot move to another screen outside the main display
- 【C语言】深度剖析文件操作 [进阶篇_ 复习专用]
- Why do requirements change during MES implementation? How to solve it?
- An example of double exponential smoothing method
- It is said that MES can improve the production efficiency of enterprises. What are the specific aspects?
- STM32与GD32标准库不完全对比表
- 移动互联网开发专业,一次关于JVM的面试经历
猜你喜欢

SEO keyword expansion - Automatic Keyword expansion software free download

Detailed explanation of slam monocular dense reconstruction

ES6 new syntax parsing

OJ daily practice - number of daffodils

Oil monkey script synchronization

【读书笔记】《经验会计与财务研究方法-原理、应用及SAS实现》 鲁桂华

Deep learning (15): instructions for kitti2bag

Redis (I): basics of redis - Introduction to redis, basic data types, general instructions, jedis

深度解析ERP和MES的六大不同之处,务必耐心看完

Unity determines whether the file (under the local absolute directory) exists
随机推荐
2022中国眼博会,北京青少年眼健康产业展会,护眼教育设备展
Redis(二):redis高级——linux下redis基本操作、持久化、事务、删除策略、服务器基础配置redis.conf、高级数据类型
内存管理、
华为Routing & Switching切换为Datacom,究竟变了些什么
面试题9——捕获的雨水II
MinIO,Zuul
Share the 28 we media tools I often use and collect them quickly. If 20000 videos are played, there will be 264 benefits
When the notebook expands the external display, the mouse cannot move to another screen outside the main display
Applet subcontracting
序列化 及 transient关键字
2022 Quality Controller - decoration direction - general basic (quality controller) examination question bank and simulation examination
Deep learning (15): instructions for kitti2bag
Blender MMD export FBX models and bake animations
2022 China eye Expo, Beijing Youth eye health industry exhibition, eye care education equipment exhibition
xxl-job 带参数执行和高可用部署
Redis source code linked list (adlist. H and adlist. C) (Part 1)
I've got an offer, and I need some knowledge for the interview
Detailed MOS tube knowledge - MOS tube high-end drive and low-end drive analysis, principle and difference
The shadow ticket rebate system developed by uniapp + PHP can operate perfectly
非常强大的时间日期插件 --- JeDate.js