From: b_sanderson@decus.ch (Bruce Sanderson ABB Process Automation)
Newsgroups: comp.os.vms
Subject: trouble reading a relative file (VAX C)
Date: 19 Aug 92 05:46:16 GMT
Organization: DECUS (Switzerland)

C Problem

While reading a relative direct access file, the program cannot read 
record number 25.
Question: What is going on? What is wrong in the program?

Partial dump, FDL file, C program follow 

Dump of file $DISK2:[IFK.EXE]TEST.IND;2 on 19-AUG-1992 07:15:32.39
File ID (2829,90,0)   End of file block 51 / Allocated 51

Record number 23 (00000017), 80 (0050) bytes

 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020
 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020
                                     20202020 20202020 20202020 20202020

Record number 24 (00000018), 80 (0050) bytes

 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020
 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020
                                     20202020 20202020 20202020 20202020

Record number 25 (00000019), 80 (0050) bytes

 20202020 20206E65 68636972 74737265 746E752F 74746566 20746669 72686353
 20202020 20202020 20202020 20202020 20202020 20202020 20202020 20202020
                                     32302020 20202020 20202020 20202020







IDENT	"19-AUG-1992 07:09:37	VAX/VMS ANALYZE/RMS_FILE Utility"

SYSTEM
	SOURCE                  VAX/VMS

FILE
	ALLOCATION              51
	BEST_TRY_CONTIGUOUS     yes
	BUCKET_SIZE             1
	CLUSTER_SIZE            3
	CONTIGUOUS              no
	EXTENSION               50
	FILE_MONITORING         no
	GLOBAL_BUFFER_COUNT     0
	MAX_RECORD_NUMBER       2147483647
	NAME                    "$DISK2:[IFK.EXE]TEST.IND;2"
	ORGANIZATION            relative
	OWNER                   [IHR,H24622]
	PROTECTION              (system:RWED, owner:RWED, group:RWED, world:)

RECORD
	BLOCK_SPAN              yes
	CARRIAGE_CONTROL        fortran
	FORMAT                  fixed
	SIZE                    80


/*-------------------------------------------*/
/*           include section                 */
/*-------------------------------------------*/
#include <sys$library:rms.h>;
#include <sys$library:stdio.h>;
 

main()
{
/*--------------------------------------------------------------------------*/
  struct FAB fab1;
  struct RAB rab1;
  char panelfile[17]="IFKSYS5:TEST.IND";
  register stat;
  int i;
  char help_rec[80];
                          /* default help panel filename */
   int rec_numero;
   int panel_nr;
   panel_nr=1;
   rec_numero = 24*(panel_nr - 1) + 1;
 /* initialize fab1 & rab1 and open file */
   fab1 = cc$rms_fab;
   rab1 = cc$rms_rab;
 
   fab1.fab$l_fna = panelfile;
   fab1.fab$b_fns = sizeof(panelfile)-1;
   fab1.fab$b_org = FAB$C_REL; /* type of file */
   fab1.fab$b_rfm = FAB$C_FIX;           /* fixed length records */
   fab1.fab$b_fac = 0;                 /*  readonly */
   fab1.fab$b_shr = FAB$M_GET;         /* shared readonly */

   rab1.rab$l_fab = &fab1;
   rab1.rab$b_rac = RAB$C_KEY;         /* access through record number */
   rab1.rab$l_kbf = &rec_numero;
   rab1.rab$b_ksz = sizeof(rec_numero);
   rab1.rab$l_ubf = &help_rec[0]; /* initialize fab & rab */
   rab1.rab$w_usz = sizeof(helprec);
   if (((stat = SYS$OPEN(&fab1)) & 1 ) != 1)
   LIB$STOP(stat);
   if (((stat = SYS$CONNECT(&rab1)) & 1 ) != 1)
   LIB$STOP(stat);

/* read in 48 records from file */
   for (i=0; i<48; i++)
   {
      if ((stat = SYS$GET(&rab1)) == RMS$_NORMAL)
      {
/* print the record */
      printf("|%s|\n",help_rec) ;
      rec_numero++;
      }
      else 
         if (stat == RMS$_RNF )
           {
           printf ("\n record %d not found ",rec_numero);
           }      
      else if (stat == RMS$_KEY || stat == RMS$_MRN )
      printf ("\n record number out of range ");
      else
      LIB$SIGNAL(rab1.rab$l_sts,rab1.rab$l_stv);
   }
      /* close file */
      if (((stat = SYS$DISCONNECT(&rab1)) & 1 ) != 1)
      LIB$STOP(stat);
      if (((stat = SYS$CLOSE(&fab1)) & 1 ) != 1)
      LIB$STOP(stat);
}

-------------------------------------------------------------------------
                              Bruce Sanderson
  "Au pays des aveugles       ABB Process Automation AG
  les borgnes sont rois"      Dept ITR
                              5401 Baden Switzerland
                              Internet: B_SANDERSON@DECUS.SWITCH.ARCOM.CH
                              X25 02284791027260::SYSTEM
                              Ph +41 56 76 88 93
                              FAX +41 56 83 30 89