t2.c
来自「linux源代码」· C语言 代码 · 共 42 行
C
42 行
#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; fd=open("/tmp/scores", O_RDONLY); if (fd==-1) { perror("open()"); exit(1); } score=mmap(NULL, sizeof(struct score_st)*32, PROT_READ, MAP_PRIVATE, fd, 0); if (score==MAP_FAILED) { perror("mmap()"); exit(1); } close(fd); for (i=0;i<32;++i) { printf("Name: %s\tMath=%d\tChinese=%d\n", score[i].name, score[i].math, score[i].chinese); } mummap(score, sizeof(struct score_st)*32); exit(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?