zoukankan      html  css  js  c++  java
  • 第二周实验补交(myod)

    实验内容

    1 复习c文件处理内容
    2 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能
    3 main与其他分开,制作静态库和动态库
    4 编写Makefile
    5 提交测试代码和运行结果截图, 提交调试过程截图,要全屏,包含自己的学号信息
    6 在博客园发表一篇博客,重点写遇到的问题和解决过程

    实验代码

    myod.c

    #include "head.h"
    #include <stdio.h>
    void main()
    { 
      char name[50];
      printf("please input the txtname:");
      scanf("%s",name);
      ascii(name);
      hex(name);
    }
    

    ascii.c

    #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:
    ");
    
      while(ch!=EOF)
      {
         if(ch=='
    ')
            printf("
    ");
         else
            printf("%4d",ch);
            ch=fgetc(fp);
      }
      fclose(fp);
    
    }
    

    hex.c

    #include "head.h"
    #include <stdio.h>
    void hex(char *name)
    {
      FILE *fp;
      char ch;
      printf("output the hex:
    ");
      fp=fopen(name,"r");
      ch=fgetc(fp);
      while(ch!=EOF)
      {
        if(ch=='
    ')
        printf("
    ");
        else
        printf("%4x",ch);
        ch=fgetc(fp);
       }
       fclose(fp);
    }
    

    head.h

    void hex(char *name);
    void ascii(chlsar *name);
    

    实验流程

    1.直接编译

    gcc *.c
    ./a.out
    

    2.用静态库
    将.o文件生成静态库(要去掉myod.c).

    gcc -c *.c -o ascii.o
    rm myod.o
    ar cr myod.a *.o
    gcc -o myod12 myod.c -L. myod.a
    

    3.用动态库
    对ascii.c和hex.c制作动态库.

    gcc -shared -fpic -o myod.so hex.c ascii.c
    gcc myod.c myod.so 
    


  • 相关阅读:
    golang获取URL
    Golang读取HTML中Table数据到二维数组
    Golang的GUI开发包fyne基本教程
    C#搭建安川机器人上位机
    程序计数器
    SpringBoot定时任务详解
    mysql 5.7安装
    springboot 配置多数据源
    mysql 查询某一天数据
    java如何获取当前日期和时间
  • 原文地址:https://www.cnblogs.com/banpingcu/p/12101663.html
Copyright © 2011-2022 走看看