Myod实验——20181307王新凯

一、实验要求:

1 复习c文件处理内容

2 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能

3. main与其他分开,制作静态库和动态库

4. 编写Makefile

5 提交测试代码和运行结果截图, 提交调试过程截图,要全屏,包含自己的学号信息

6 在博客园发表一篇博客,重点写遇到的问题和解决过程
二、实验准备
1.od命令:od命令用于输出文件的八进制、十六进制或其它格式编码的字节,通常用于显示或查看文件中不能直接显示在终端的字符。
常见的文件为文本文件和二进制文件。此命令主要用来查看保存在二进制文件中的值。
2.代码准备:
  2.1ASCII代码:
    
  #include "head.h"
  #include <stdio.h>
  void ascii(char *name)
  {
        FILE *fp;
        char ch;
        fp=fopen(name,"r");
        ch=fgetc(fp);
        printf("output the ascii:\n");
    while(ch!=EOF)
    {
       if(ch=='\n')
          printf("\n");
       else
          printf("%4d",ch);
          ch=fgetc(fp);
    }
    fclose(fp)    
  }
  2.2十六进制代码:  #include "head.h"
  #include <stdio.h>
  void hex(char *name)
  {
    FILE *fp;
    char ch;
    printf("output the hex:\n");
    fp=fopen(name,"r");
    ch=fgetc(fp);
    while(ch!=EOF)
    {
      if(ch=='\n')
      printf("\n");
      else
      printf("%4x",ch);
      ch=fgetc(fp);
     }
     fclose(fp);
  }
  2.3主函数:
   #include "head.h"
  #include <stdio.h>
  void main()
  { 
    char name[50];
    printf("please input the txtname:");
    scanf("%s",name);
    ascii(name);
    hex(name);
  }
  2.4头文件:
 
  void hex(char *name);
  void ascii(char *name);
三、实验开始
1.创建一个txt文件xinkai1307.txt 内容为1307

 

 2.写入上述函数

 

  4.编译,运行

 

 5.制作静态库

 

 

 

 

6.制作动态库:

 

 

 7.makefile

 

posted @ 2020-10-11 17:32  XK12138  阅读(95)  评论(0编辑  收藏  举报