#include <fcntl.h> #include <unistd.h> #include <stdio.h> int main(void) { int fd; char buf[20]; int size; off_t location; char * filename = "tt.dat"; if( (fd = open(filename,O_RDWR | O_CREAT | O_TRUNC)) == -1){ perror("open"); return 1; } size = write(fd,"Hello C Programming!\n",20); if(size <0){ perror("write"); return 1; } printf("%d bytes write to %s successfully!\n",size,filename); printf("the offset now is: %d\n",lseek(fd,0,SEEK_CUR)); if( (location = lseek(fd,5,SEEK_SET) > -1)){ printf("after lseeked %d .the offset now is: %d\n",location,lseek(fd,0,SEEK_CUR)); } size = read(fd,buf,5); if(size <0){ perror("read"); return 1; } printf("%d bytes(\"%s\") read from %s successfully!\n",size,buf,filename); printf("the offset now is: %d\n",lseek(fd,0,SEEK_CUR)); return 0; } |
原帖由 cugb_cat 于 2008-1-22 14:37 发表
因为你这句的括号括错地方了
if( (location = lseek(fd,5,SEEK_SET) > -1)){
printf("after lseeked %d .the offset now is: %d\n",location,lseek(fd,0,SEEK_CUR));
}
if( (location = lseek(fd,5,SEEK_SET) > -1)){
if( (location = lseek(fd,5,SEEK_SET)) > -1){
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |