delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/21/11:49:00

From: "Ian Pitt" <IanPitt AT worldnet DOT att DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Screen Builder
Date: 20 Jun 1997 23:05:55 GMT
Organization: AT&T WorldNet Services
Lines: 17
Message-ID: <01bc7dce$e940bc00$c3c074cf@ian>
Reply-To: "Ian Pitt" <Ian_Pitt AT bigfoot DOT com>
NNTP-Posting-Host: 207.116.192.195
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This is a multi-part message in MIME format.

------=_NextPart_000_01BC7DAD.623843C0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Are there any screen builders for Allegro or for JPTUI?
------=_NextPart_000_01BC7DAD.623843C0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<html><head></head><BODY bgcolor=3D"#C8E0D8"><p><font size=3D2 =
color=3D"#000000" face=3D"Arial">Are there any screen builders for =
Allegro or for JPTUI?</p>
</font></body></html>
------=_NextPart_000_01BC7DAD.623843C0--

      {

>                 fin >> tmpBuffer;

I'm not sure, does this really read the next 128 bytes from the input

stream (including a terminating '0' character)??

> 

>                 // allocate memory to hold word

>                 wordBuffer[n] = new char [(strlen(tmpBuffer))];

I think you'll need to allocate at least strlen(tmpBuffer) + 1 bytes

here to hold the terminating '0' character of the string.

> 

>                 // copy string to newly allocated space

>                 strcpy(wordBuffer[n], tmpBuffer);

> 

>                 n++;

>         } while(!fin.eof());

> 

>         fin.close();

> }

> 

> What am I missing?  The DJGPP accepts this and various other attempts

> such as stuffing a pointer in front of the pointer array, the only

> thing I can get it to do is GPF or store only the first character

Excuse my ignorance, but what do you mean with 'GPF'?

> in the buffer.

> 

I think your function above does the following inside the loop:

- read 1 character from the input stream to tmpBuffer 

- since you're lucky, tmpBuffer is initialized with '0' characters

- then you allocate strlen(tmpBuffer) = 1 bytes memory for your 

  ptr (internally the minimum mem allocation segment will be assigned,

  a power of 2 number of bytes, I'm not sure what's the smallest but

  I think at least 2^8 = 256 bytes)

- it will be assigned correctly to the next index slot in the array

- the strcpy will transfer the 1 byte from tmpBuffer to the ptr

- you're still lucky, because the tmpBuffer terminates with a '0' 

  character and the wordBuffer[n] keeps more than 1 byte



HTH

Günther



-- 

~~o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 O o  __/|_   "I'm swimming,     | Guenther Makulik

   O /*    \/| I'm swimming ..." | E-Mail:   makulik AT evolution DOT org

     \_U___/\| (Sonic Youth)     |

http://members.evolution.org/gmakulik/

- Raw text -


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