t1.c

来自「linux源代码」· C语言 代码 · 共 38 行

C
38
字号
#include <stdio.h>#include <fcntl.h>#include <sys/mman.h>#define NAMESIZE 32struct score_st {	char name[NAMESIZE];	int math;	int chinese;};intmain(){	int i;	int fd;	struct score_st score[32];	fd=open("/tmp/scores", O_WRONLY|O_CREAT|O_TRUNC, 0600);	if (fd==-1) {		perror("open()");		exit(1);	}	for (i=0;i<32;++i) {		snprintf(score[i].name, NAMESIZE, "stu%d", i+1);		score[i].math=rand()%101;		score[i].chinese=rand()%101;	}	write(fd, score, sizeof(struct score_st)*32);	close(fd);	exit(0);}

⌨️ 快捷键说明

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