第二周作业 20155210 潘滢昊

第二周作业

测试4静态库的测试

ar rcs mymath.a add.o sub.o div.o mul.o

gcc -static -o 5210 main.o ./mymath.a

./5210

截图:

测试5共享库

gcc -shared -fpic -o libmymath.so add.c div.c mul.c sub.c

gcc -o 5210_2 main.c ./libmymaht.so

./5210_2

截图:

myod

head.h:

#ifndef HEAD_H
#define HEAD_H
#include<stdio.h>
#include<stdlib.h>
void ascii(char *name);
void sixteen(char *name);
#endif

ascii.c:

void ascii(char *name)
{
    FILE *fp;
    char ch;
    fp=fopen(name,"r");
    ch=fgetc(fp);
    printf("ascii码输出为:\n");
    while(ch!=EOF)
    {
        if(ch=='\n') 
            printf("\n");
        else 
            printf("%d ",ch);
        ch=fgetc(fp);
    }
}

sixteen.c:

void sixteen(char *name)
{
    FILE *fp;
    char ch;
    printf("16进制输出为:\n");
    fp=fopen(name,"r");
    ch=fgetc(fp);
    while(ch!=EOF)
    {
        if(ch=='\n') 
            printf("\n");
        else
            printf("%x ",ch);
        ch=fgetc(fp);
    }
    fclose(fp);
}

main:

void main(){

    char name[50];
    printf("od -tx -tc ");
    scanf("%s",name);
    ascii(name);
    printf("\n");
    sixteen(name);
}

截图:

动态库截图:

静态库截图:

makefile

testmymath: main.o add.o sub.o mul.o div.o

(Tab)gcc main.o add.o sub.o mul.o div.o -o testmymath

main.o: main.c head.h

(Tab)(Tab)(Tab)(Tab)gcc -c main.c

add.o: add.c head.h

(Tab)(Tab)(Tab)gcc -c add.c

sub.o: sub.c head.h

(Tab)(Tab)gcc -c sub.c

mul.o: mul.c head.h

(Tab)gcc -c mul.c

div.o: div.c head.h

(Tab)gcc -c div.c

截图:

代码托管

posted @ 2017-09-29 16:33  20155210潘滢昊  阅读(182)  评论(2编辑  收藏  举报