Content Experiments
1 review c file processing
2 write myod.c achieved under Linux od -tx -tc XXX XXX function with MyoD
3 main and separate, making the static and dynamic libraries other
4 write Makefile
5 to submit the results of the test code and run shots, submit Screenshot commissioning, to full-screen, contains its own student number information
6 published a blog in blog Park, problems encountered and solutions focus on writing process
Experiment Code
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:\n");
while(ch!=EOF)
{
if(ch=='\n')
printf("\n");
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:\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);
}
head.h
void hex(char *name);
void ascii(chlsar *name);
experiment process
1. Direct compilation
gcc *.c
./a.out
2. Use static library
will generate static library .o files (to remove 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. dynamic libraries
to create dynamic library of ascii.c and hex.c.
gcc -shared -fpic -o myod.so hex.c ascii.c
gcc myod.c myod.so