首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

pread困惑:pread读完后,将指向后一个位置吗

2012-11-20 
pread疑惑:pread读完后,将指向后一个位置吗?C/C++ code/****************************stu.dat数据结构int

pread疑惑:pread读完后,将指向后一个位置吗?

C/C++ code
/****************************stu.dat数据结构     int no;    char name[20];    float score;*****************************/#include <stdio.h>#include <fcntl.h>#include <stdlib.h>#include <unistd.h>int main(){    int fd;    fd=open("stu.dat",O_RDONLY);    if(fd==-1) printf("open err::%m\n"), exit(-1);        int i;        float score;    int no;    for(i=0;i<2;i++)    {        pread(fd,&score,sizeof(float),i*28+24);  //读取学生的成绩        printf("%.2f\n",score);                read(fd,&no,4);  //这个应该是定位到了下一条记录的int no学生编号了吧?        printf("%d\n",no);  //但这里打印出来的却不是int no学生编号,很奇怪!是什么原因    }        close(fd);        return 0;}


------------------------
read(fd,&no,4); //这个应该是定位到了下一条记录的int no学生编号了吧?
printf("%d\n",no); //但这里打印出来的却不是int no学生编号,很奇怪!是什么原因

高手帮忙看一下,谢谢


[解决办法]
The file offset is not changed.
pread 是不会改变偏移量的值的,read会改变。

热点排行