delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/23/02:03:49

Date: Tue, 23 Jan 1996 07:49:32 +0100
To: djgpp AT delorie DOT com
From: andrea DOT tasso AT galactica DOT it (Andrea Tasso)
Subject: problem with fseek, macro SEEK_CUR does not work

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