Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!rutgers!bellcore!texbell!nuchat!uhnix1!sysmgr.cs.uh.edu!jsmng From: jsmng@sysmgr.cs.uh.edu Newsgroups: comp.lang.c Subject: lseek problem Message-ID: <14657@uhnix1.uh.edu> Date: 8 Oct 89 09:08:29 GMT Sender: nntppost@uhnix1.uh.edu Reply-To: jsmng@sysmgr.cs.uh.edu () Organization: University of Houston Lines: 38 I have a small problem about lseek. I tried to use the following program to lseek a file ( with numbers 1 2 3 ). I expect to get back 1, blank, and 1 again. But my output was 1, blank and 2. Initially I use fscanf(fp,"%f",&float_variable) in place of fgetc and received 1 2 3 instead of 1 2 1. Can anyone tell me what I did wrong? Thanks. I think this is probably something simple so please just send me a mail and I will summarize it. #include #include #include main(argc,argv) int argc; char *argv[]; { FILE *fp; char c1,c2,c3; if ((fp = fopen(argv[1],"r")) == NULL) { perror("cannot open file"); exit(1); } c1 = fgetc(fp); printf("first number = %c\n",c1); c2 = fgetc(fp); printf("second number = %c\n",c2); if (lseek(fp,0,L_SET) == NULL) { perror("lseek error"); exit(1); } c3 = fgetc(fp); printf("first number again = %c\n",c3); }