⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read.c

📁 《linux驱动程序设计从入门到精通》一书中所有的程序代码含驱动和相应的应用程序
💻 C
字号:
/* * This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2007, 2010 fengGuojin(fgjnew@163.com) */#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <fcntl.h>main(){	int fd;	char num[2];	fd = open("/dev/fgj", O_RDWR, S_IRUSR | S_IWUSR);	if (fd != - 1)	{		while (1)		{			read(fd, &num,2); //程序将阻塞在此语句			printf("The data is %s\n", num);			//如果输入是5,则退出			if (num[1] ==0x35)			{				close(fd);				break;			}		}	}	else	{		printf("device open failure\n");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -