Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28603 Discussions

fgetc skips characters in binary file

booker
Beginner
574 Views
I have a simple 131 byte file that I am trying to read with fgetc using
ifort 10.1.008. Here is the code:

integer fgetc,ichar
integer i,j
character*1 ctmp

i=0
j=0
do while (j.ge.0)
j=fgetc(5,ctmp)
i=i+1
if(j.ge.0)then
write(6,'(i4,a,i4)')i,' ',ichar(ctmp)
else
write(6,*)'at EOF'
endif
end do

stop
end

This code reports only 130 bytes in the file. It is skipping the 41st byte which
happens to be an ascii code 13 (carriage return). There are however other identical
bytes elsewhere in the file. Both g77 and gfortran read the file correctly.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
574 Views
Please report this to Intel Premier Support.
0 Kudos
Reply