test_demo.c
来自「UP-NETARM3000下教材实例源码,其中提供了多个实验内容源码,使用ARM」· C语言 代码 · 共 52 行
C
52 行
#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <sys/ioctl.h>void showbuf(char *buf);int MAX_LEN=32;int main(){ int fd; int i; char buf[255]; for(i=0; i<MAX_LEN; i++){ buf[i]=i; } fd=open("/dev/demo",O_RDWR); if(fd < 0){ printf("####DEMO device open fail####\n"); return (-1); } printf("write %d bytes data to /dev/demo \n",MAX_LEN); showbuf(buf); write(fd,buf,MAX_LEN); printf("Read %d bytes data from /dev/demo \n",MAX_LEN); read(fd,buf,MAX_LEN); showbuf(buf); ioctl(fd,1,NULL); ioctl(fd,4,NULL); close(fd); return 0;}void showbuf(char *buf){ int i,j=0; for(i=0;i<MAX_LEN;i++){ if(i%4 ==0) printf("\n%4d: ",j++); printf("%4d ",buf[i]); } printf("\n*****************************************************\n");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?