delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/19/10:48:34

Date: Fri, 19 Jan 1996 16:31:29 +0100
To: djgpp AT delorie DOT com
From: andrea DOT tasso AT planet DOT it (Andrea Tasso)
Subject: fseek with SEEK_CUR does not work also in binary mode

HI !
First: excuse me for my previous message about undefined reference with math 
that I posted twice.

Now I have a problem with the function fseek, that I explain with this example:

This is the code:


#include <stdio.h> 
#include <stdlib.h> 

void main ( void )

{

  FILE *fp ; 
  if ( ( fp = fopen ( "test" , "rb" ) ) == NULL ) 
       {
          printf ( " Cannot open file for input. \n " ) ;
          exit (1) ;
       }
    
  printf ( "%c\n" , getc(fp) ) ;
  fseek ( fp , +1 , SEEK_CUR ) ;
  printf ( "%c\n" , getc(fp) ) ;

} 


The text input file name test is this line:

1234567890


The output is:

1


While I expected to see
1
3


That is what I see if I write

fseek ( fp , +2 , SEEK_SET ) ;



The problem remains also if I open the file in text mode; I tried to open it 
in binary mode because I read in djgpp documentation that fseek doesn't work 
properly with DOS in text mode (no one-to-one correspondence chars-bytes).
I am afraid the problem is pesent also in binary mode, isn't it ?

Thank you

andrea

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019