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);
}
编写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);
}
编写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);
}
}
编译并运行
创建一个文本文件作为输出
运行结果
静态库
共享库