delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/14/18:31:20

Date: Mon, 13 Sep 1999 02:01:56 +0700
From: Batchex <thedark1 AT Phreaker DOT net>
X-Mailer: The Bat! (v1.32) S/N E34104EF
X-Priority: 3 (Normal)
Message-ID: <1684.990913@Phreaker.net>
To: djgpp AT delorie DOT com
Subject: invalid operands
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Hi,

  I have  a difficulty with the code below :

  FILE *fp;
  int nIdx, nNumEntries;
  long lnDataStart, lnFileSize;
  char **lpszTable;

  // clipped

  lpszTable = (char **)malloc(nNumEntries*sizeof(char *));
  fread(lpszTable,sizeof(char *),nNumEntries,fp);
  lnDataStart = (long)lpszTable[0];
  lpszTable[0] = (char *)malloc((lnFileSize-lnDataStart)*sizeof(char));

  for(nIdx=1;nIdx<nNumEntries;nIdx++)
   lpszTable[nIdx]=(char *)(lpszTable[0]+(lpszTable[nIdx]-lnDataStart));

  NOTE : fp, nNumEntries & lnFileSize is initialized somewhere else
  before the above code.

  The last line of the code always gives me "invalid operands for
  binary +". If lpszTable[0] is not malloc()ed before the for loop, it
  compiles and run fine. I have tried some variations for the
  assignment, and I think the lpszTable[0] operand is the culprit.
  What I need is to load some data to an allocated buffer, load the
  entries offsets to another allocated buffer ('cause the entries have
  variable lengths), then add the offsets to the address of the
  allocated data buffer (the first allocated buffer). How can I do
  this if adding lpszTable[0] with some value gives "invalid operands
  for binary +"?

  One other question, not related to the above code, anybody know any
  function that can read raw data from file (like _dos_read()) that is
  POSIX compliant? fread() seems to stop whenever it encounter CR/LF
  pair ("\n"), and my data have a lot of them.

  Thanks in advance for any suggestions.

Batchex
mailto:thedark1 AT Phreaker DOT net


- Raw text -


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