myod
要求
- 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能
编写myod.c
#include<stdio.h>
#include<stdlib.h>
void main()
{
char filename[50];
void Hexa(char *filename);
void ascii(char *filename);
printf("input filename: ");
scanf("%s",filename);
ascii(filename);
Hexa(filename);
}
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164558639-1658987322.png)
编写hex.c
#include<stdio.h>
#include<stdlib.h>
void Hexa(char *filename)
{
FILE *fp;
char ch;
printf("Hexadecimal numbers:
");
fp=fopen(filename,"r");
ch=fgetc(fp);
while(ch != EOF)
{
if(ch=='
')
{
printf("
");
}
else
{
printf("%x, ",ch);
}
ch=fgetc(fp);
}
fclose(fp);
}
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164620522-1850237000.png)
编写ASCII.c
#include<stdio.h>
#include<stdlib.h>
void ascii(char *filename)
{
FILE *fp;
char ch;
fp=fopen(filename,"r");
ch=fgetc(fp);
printf("ascii:
");
while(ch != EOF)
{
if(ch=='
')
{
printf("
");
}
else
{
printf("%d, ",ch);
}
ch=fgetc(fp);
}
}
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164631589-1361991244.png)
编译并运行
创建一个文本文件作为输出
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164714333-741024208.png)
运行结果
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164734691-1499707600.png)
静态库
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164757817-1682587103.png)
共享库
![](https://img2018.cnblogs.com/blog/1800800/201912/1800800-20191228164805539-91468550.png)