1 Star 0 Fork 0

protectm20155316/Computer Systems - 20155316

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
myod.c 983 Bytes
一键复制 编辑 原始数据 按行查看 历史
protectm20155316 提交于 2017-10-11 16:57 +08:00 . myod
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define LENGTH 16
/**
* 仿照linux命令: od -tx1 -tc 文件地址
* 传入文件地址
*/
void myod(char *address)
{
int fd;
int line_count=0;
int sum_count=0;
int i=0;
char ch[LENGTH];
if((fd=open(address, O_RDONLY))==-1)
{
perror(address);
exit(1);
}
while((line_count=read(fd, ch, sizeof(char)*16))>0)
{
sum_count += line_count; //开头的八进制表示
printf("%07o ", sum_count);
for(i=0; i<LENGTH; i++) //第一行,二进制表示
{
printf("%-4d", ch[i]);
}
printf("\n ");
for(i=0; i<LENGTH; i++) //第二行,对应的字符
{
if(ch[i]=='\n') printf("\\n "); //将'\n'输出至屏幕
else printf("%-4c", ch[i]);
}
printf("\n");
}
close(fd);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/protectmonarch/Computer-Systems---20155316.git
git@gitee.com:protectmonarch/Computer-Systems---20155316.git
protectmonarch
Computer-Systems---20155316
Computer Systems - 20155316
master

搜索帮助