第二周选答题-myod
作者:互联网
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: \n");
fp=fopen(filename,"r");
ch=fgetc(fp);
while(ch != EOF)
{
if(ch=='\n')
{
printf("\n");
}
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: \n");
while(ch != EOF)
{
if(ch=='\n')
{
printf("\n");
}
else
{
printf("%d, ",ch);
}
ch=fgetc(fp);
}
}
编译并运行
创建一个文本文件作为输出
运行结果
静态库
共享库
标签:fp,ch,答题,filename,char,第二周,printf,include,myod 来源: https://www.cnblogs.com/dhr9313/p/12112252.html