小海螺预祝大家都能过!Makefile 文件程序 p77 题目不固定 放两个例题
main:main.o mytool1.o mytool2.o
gcc -o main main.o mytool1.o mytool2.o
main.o:main.c
gcc -c main.c
mytool1.o:mytool1.c mytool1.h
gcc -c mytool1.c
mytool2.o:mytool2.c mytool2.h
gcc -c mytool2.c
sum:ex_sum.o mysum.o
gcc ex_sum.o mysum.o -o sum
ex_sum.o: ex_sum.c
gcc -c ex_sum.c
mysum.o: mysum.c mysum.h
gcc -c mysum.c
shell脚本程序(整除) p86
例题:编写显示20以内能被3整除的数的shell脚本程序
#! /bin/bash
for((i=1;i<20;i++))
do
if(( i% 3 == 0 ))
then
echo $ i
fi
done
同时控制两个LED灯的点亮或熄灭的程序 p93-94
volatile unsigned int *GPC0CON=(volatile unsigned int *) 0xE0200060;
volatile unsigned int *GPC0DAT=(volatile unsigned int *) 0xE0200064;
void delay()
{
int k=0x100000;
while (k--);
}
int main(void)
{
int i=0;
*GPC0CON &= ~0xff000;
*GPC0CON |=0x11000;
while (1)
{
*GPC0DAT &= ~(3<<3);
*GPC0DAT |=i<<3;
i++;
if(i==4){i=0;}
delay();
}
return 0;
}
文件的创建和读写程序 p121 例6-2 6-3
#include
#include
#include
Int mian()
{
Int fd;
fd=open("b.txt",O_CREAT|O_TRUNC|O_RDWR,0666);
printf(("create_file:b.txtfd=%d\n",fd);
char *buf="this is a embedded course!";
int len=strien(buf);
int size=write(fd,buf,len);
lseek(fd,0,SEEK_SET);
char buf1[50];
int size1=read(fd,buf1,50);
printf("size1=%d,b.txt context are:%s\n",size1,buf1);
close(fd);
return0;
}
#include
#include
int main()
{
int x,fd[2];
char buf[50],s[50];
pipe(fd);
x=fork();
if(x==0)
{
close(fd[1]);
sleep(1);
read(fd[0],s,sizeof(s));
printf(“read string:%s\n”,s);
close(fd[0]);
exit(0);
}
else if(x>0)
{
close(fd[0]);
sprintf (buf,”this is an another pipe!”);
write(fd[1],buf,sizeof(buf));
close(fd[1]);
wait(x,NULL,0);
exit(0);
}
}
#include
#include
int main(int argc,char * argv[])
{
int shm_id;
char * shm_buf,str[50];
shm_id = atoi(argv[1]);
shm_buf = shmat(shm_id,0,0)
printf("读取共享内存数据:\n");
sprintf(str,shm_buf);
printf("%s \n",str);
system("ipcs -m");
}
#include
#include
int main(int argc,char * argv[])
{
int shm_id;
char * shm_buf;
shm_id = atoi(argv[1]);
shm_buf = shmat(shm_id,0,0)
shmdt(shm_buf);
shmctl(shm_id,IPC_RMID,NULL);
system("ipcs -m");
}