rd.c

来自「linux unix 入门代码上,是关于初级入门的,经典代码」· C语言 代码 · 共 43 行

C
43
字号
#include <stdio.h>#include <fcntl.h>#include <sys/types.h>struct stu_r {	int id;	char name[64];	int chinese;	int english;	int math;};intmain(){	struct stu_r stu[10];	int i,ret;	int fd;	fd=open("/tmp/score",O_RDONLY);	if (fd==-1) {		perror("open()");		exit(1);	}	ret=read(fd,stu,sizeof(struct stu_r)*10);	if (ret<sizeof(struct stu_r)*10) {		fprintf(stderr,"Only %d bytes loaded.\n",ret);	} else {		fprintf(stderr,"Loaded.\n");	}	close(fd);	for (i=0;i<ret/sizeof(struct stu_r);i++) {		printf("Student: Name=%s(%d)\n",stu[i].name,stu[i].id);		printf("\tmath=%d\n\n",stu[i].math);	}	exit(0);}

⌨️ 快捷键说明

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