zoukankan      html  css  js  c++  java
  • 20191317王鹏宇MyOD

    Linux MyOD


    实践内容:MyOD
    代码:
    20191317wpy.h

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #define INPUT_FILE "20191317wpy.txt"
    void myod(char transform[],int num);
    

    main.c

    #include "20191317wpy.h"
    
    int main()
    {
        char transform[1000]={0};
        char filename[128]={0};
        int num = 0;
        int n=0;
        char c;
    
        FILE *fp;  
        /*printf("file name: 
    ");
        scanf("%s",&filename);   */
        fp = fopen(INPUT_FILE,"r");
        fread(transform,1000,sizeof(char),fp);
        while (transform[n]!=0)
        {
            num++;
            n++;
        }
        printf("%d",num);
        myod(transform,num);
        return 0;
    }
    

    myod.c

    #include "20191317wpy.h"
    
    void myod(char transform[],int num)
    {
        int count_1 = 0;
        int count_2 = 0;
        int i = 0;
        int flag = 0;
        int m = 1;
        int judge = 1;
        char tmp[3];
        while (1)
        {
            printf("%07o",count_1);
            printf("        ");
            for ( count_2 = 0; count_2 < 4; count_2++)
            {
                for (i = 3; i >= 0 ; i--)
                {
                    tmp[i] = transform[m*4-1-i];
                }
                for ( i = 0; i <= 3; i++)
                {
                    printf("%02x",tmp[i]);
                    if (tmp[i] == 0)
                    {
                        flag = 1;
                    }
                    else if (flag == 1 && i == 3)
                    {
                        judge++;
                        printf("
    ");
                        printf("          ");
                        for ( i = count_1; i < num+1; i++)
                        {
                            printf("%c   ",transform[i]);
                        }
                        printf("\n");
                        printf("
    ");
                        printf("%07o
    ",num);
                        return;
                    }
                }
                printf("        ");
                m++;
            }
            printf("
    ");
            printf("          ");
            for ( i = count_1; i < count_1+16; i++)
            {
                printf("%c   ",transform[i]);
            }
            printf("
    ");
            count_1=count_1+16;
        }
    }
    

    动态库制作Makefile
    Makefile

    main2: libmymath.so include/20191317wpy.h
    	gcc src/main.c -o bin/main2 -I/home/wpy/桌面/testmyod/include -Llib -lmymath
    	
    
    libmymath.so: myod2.o 
    	gcc -shared -o lib/libmymath.so lib/myod2.o
    
    myod2.o: src/myod.c include/20191317wpy.h
    	gcc -fPIC -c src/myod.c -I/home/wpy/桌面/testmyod/include -o lib/myod2.o
    
    clear:
    		rm lib/*.o
    start:
    		export LD_LIBRARY_PATH=lib
    		bin/main2
    

    静态库制作makefile

    main: libtestmath.a include/20191317wpy.h
    	gcc src/main.c -o bin/main -I/home/wpy/桌面/testmyod/include -Llib -ltestmath
    
    libtestmath.a: myod.o 
    	ar rcvs -o lib/libtestmath.a lib/myod.o 
    
    myod.o: src/myod.c include/20191317wpy.h
    	gcc -c src/myod.c -I/home/wpy/桌面/testmyod/include -o lib/myod.o
    
    clear:
    		rm lib/*.o
    start:
    		bin/main
    

    实践截图:

    可以从输出结果看出,od -tx -tc 20191317.txt指令与我的make指令输出结果并没有明显差异,几乎完全相同。下图是20191317.txt文件的内容:



    实践内容:静态库制作

    主要指令有:

    gcc -c src/myod.c -I/home/wpy/桌面/testmyod/include -o lib/myod.o
    ar rcvs -o lib/libtestmath.a lib/myod.o 
    gcc src/main.c -o bin/main -I/home/wpy/桌面/testmyod/include -Llib -ltestmath
    

    实践截图:


    动态库制作:
    主要指令:

    gcc -fPIC -c src/myod.c -I/home/wpy/桌面/testmyod/include -o lib/myod2.o
    gcc -shared -o lib/libmymath.so lib/myod2.o
    gcc src/main.c -o bin/main -I/home/wpy/桌面/testmyod/include -Llib -ltestmath
    

    实践截图:

    遇到问题:

    主要是在编写myod代码是遇到较多问题,如果不参考他人的代码,自己从零开始写还是比较困难,以后还是需要多加练习这一薄弱环节。其中问题比较严重的有,缓冲区溢出,这是在将文本文件中的字符提取到字符串数组中遇到的,修改了一下提取字符的代码才解决,还有就是如何打印一行16进制转化结果,隔一行ascii码,这里我采取的是利用printf可以直接打印16进制字符不用转换的方法,取了个巧,但是也算解决了这个问题。还有就是openeuler系统中安装中文环境,实在是太麻烦,在安装fcitx输入法时,各种依赖缺失,安装完一个又会提醒另一个,套来套去就是无法安装成功,所以最终我还是放弃了在openeuler系统中输出中文的方法。毕竟不是很需要在虚拟机中输出中文。

  • 相关阅读:
    转移到新的个人独立博客。
    hdu5618 (三维偏序,cdq分治)
    平衡树维护动态凸包
    poj1986 LCA
    hdu2586 LCA
    LCA最近公共祖先 ST+RMQ在线算法
    hdu 3401 单调队列优化DP
    【转】单调队列优化DP
    CodeForces 548D 单调栈
    hdu3530 单调队列
  • 原文地址:https://www.cnblogs.com/wpy-1049363419/p/15339475.html
Copyright © 2011-2022 走看看