delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/26/15:30:28

From: "RoB" <rel8ivity AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Strings in DJGPP
Date: Thu, 26 Feb 1998 15:29:51 -0500
Organization: Erol's Internet Services
Lines: 340
Message-ID: <6d4jbv$337$1@winter.news.erols.com>
NNTP-Posting-Host: 207-172-202-38.s38.as1.xwp.erols.com
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_0019_01BD42CB.61337B00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

i was writing a cpp program.  in this program i marked a variable as:

char* data

i then made this a string of [30]:

{
size =3D strlen(init);
data =3D new char[size + 1];
assert(data !=3D 0);
strcpy(data, init);
}

where "init" was just nothing  ""  ... i'm just initializing here...

okay then i entered into the new array i a name just a buncha characters =
from instream:
my input operator looks like this:
{
    char c;
    int nws;
    int i =3D 0;
   =20
    do {
        c =3D cin.peek();
        if (c =3D=3D ' ' || c =3D=3D '\n' || c =3D=3D '\t' || c =3D=3D =
'\r') {
        cin.get();         // checking for white space
        nws =3D 0;
        }
        else
            nws =3D 1;
    } while (nws =3D=3D 0);

    while (i < string::max && input.peek() !=3D '\n') {  // getting =
string... until
                                                       // control  "/n"
        right.data[i++] =3D input.get();                 // or whatever  =
"/@$#!@#%" ...
    }

    right.data[i] =3D '\0';  // making the last element in the array =
"\0"
    cin.ignore();   // getting rid of the control
    return input;   // blah blah...
}

i know this seems very cumbersome.  but, this is the way i had to do =
it...


okay, the problem lies in the output!  when i print the output to output =
stream (stdout or file)  i only get 4 chars!!! and an upside down U... i =
guess its an omega??? i don't really know...

my output command is this:

{
output << right.data;  // where right.data is of type specified above...
return output;
}

so am i doing something wrong in my code or is this something about =
djgpp i have to configure?

btw: this works on sun solaris @ school...  i get correct output...

grassyass...

plz respond to:

       ,-~~-.___.
      / |  '     \       The words of the prophets are not
     (  )         0      as sweet as the beat of the drums
      \_/-, ,----'       in the souls of our feet.
         =3D=3D=3D=3D           //
        /  \-'~;    /~~~(O)                   \,`/ /
       /  __/~|   /       |                  _)..  `-
     =3D(  _____| (_________|                 ( __  -\
   +=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D              =
   '`.
   | rel8ivity AT erols DOT com      |                ( \>_-_,
   =3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+              =
  _||_ ~-/    -RoB

------=_NextPart_000_0019_01BD42CB.61337B00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT face=3DCourier>i was =
writing a cpp=20
program.&nbsp; in this program i marked a variable =
as:</FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT face=3DCourier>char* =

data</FONT></FONT><FONT face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT face=3DCourier>i =
then made this a=20
string of [30]:</FONT></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>{</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT face=3DCourier>size =3D=20
strlen(init);</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>data =3D new char[size + 1];</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>assert(data !=3D 0);</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>strcpy(data, init);</FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2>}</FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT=20
face=3DCourier></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT face=3DCourier>where =

&quot;init&quot; was just nothing&nbsp; &quot;&quot;&nbsp; ... i'm just=20
initializing here...</FONT></FONT><FONT =
face=3DCourier></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2>okay then i entered into the new =
array i a name=20
just a buncha characters from instream:</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>my input operator =
looks like=20
this:</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT><FONT =
face=3D"Courier New"=20
size=3D2><FONT face=3DCourier></FONT></FONT><FONT color=3D#000000 =
face=3DCourier=20
size=3D2>{</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier>&nbsp;&nbsp;&nbsp; char=20
c;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp; int nws;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp; int i =3D 0;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier></FONT></FONT><FONT color=3D#000000 face=3DCourier=20
size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier>&nbsp;&nbsp;&nbsp; do=20
{</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c =3D=20
cin.peek();</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (c =3D=3D ' =
' || c =3D=3D=20
'\n' || c =3D=3D '\t' || c =3D=3D '\r') {</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
cin.get();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // checking =
for white=20
space</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nws =3D=20
0;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3D"Courier New" size=3D2><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
else</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
nws =3D 1;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp; } while (nws =3D=3D =
0);</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier>&nbsp;&nbsp;&nbsp; while=20
(i &lt; string::max &amp;&amp; input.peek() !=3D '\n') {&nbsp; // =
getting=20
string... until</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
// control&nbsp; &quot;/n&quot;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
right.data[i++] =3D=20
input.get();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
// or whatever&nbsp; &quot;/@$#!@#%&quot; ...</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3D"Courier New" size=3D2><FONT face=3DCourier>&nbsp;&nbsp;&nbsp;=20
}</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier>&nbsp;&nbsp;&nbsp;=20
right.data[i] =3D '\0';&nbsp; // making the last element in the array=20
&quot;\0&quot;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp; cin.ignore();&nbsp;&nbsp; // getting =
rid of the=20
control</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier>&nbsp;&nbsp;&nbsp; return input;&nbsp;&nbsp; // blah=20
blah...</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
color=3D#000000 face=3DCourier size=3D2>}</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>i know this seems =
very=20
cumbersome.&nbsp; but, this is the way i had to do it...</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>okay, the problem =
lies in the=20
output!&nbsp; when i print the output to output stream (stdout or =
file)&nbsp; i=20
only get 4 chars!!! and an upside down U... i guess its an omega??? i =
don't=20
really know...</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>my output command is=20
this:</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT><FONT =
face=3D"Courier New"=20
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>{</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>output &lt;&lt; =
right.data;&nbsp; // where=20
right.data is of type specified above...</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>return =
output;</FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT><FONT color=3D#000000 =
face=3DCourier=20
size=3D2>}</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>so am i doing something wrong =
in my code or=20
is this something about djgpp i have to configure?</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>btw: this works on sun solaris =
@=20
school...&nbsp; i get correct output...</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier>grassyass...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>plz respond to:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
,-~~-.___.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; / |&nbsp; =
'&nbsp;&nbsp;&nbsp;&nbsp;=20
\&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The words of the prophets are=20
not<BR>&nbsp;&nbsp;&nbsp;&nbsp; (&nbsp;=20
)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as sweet as the beat of the=20
drums<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_/-,=20
,----'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in the souls of our=20
feet.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
=3D=3D=3D=3D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

//<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&nbsp; =
\-'~;&nbsp;&nbsp;&nbsp;=20
/~~~(O)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
\,`/ /<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&nbsp; __/~|&nbsp;&nbsp; =

/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
_)..&nbsp; `-<BR>&nbsp;&nbsp;&nbsp;&nbsp; =3D(&nbsp; _____|=20
(_________|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
( __&nbsp; -\<BR>&nbsp;&nbsp;=20
+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
'`.<BR>&nbsp;&nbsp; | <A=20
href=3D"mailto:rel8ivity AT erols DOT com">rel8ivity AT erols DOT com</A>&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;=20
( \&gt;_-_,<BR>&nbsp;&nbsp;=20
=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
_||_ ~-/&nbsp;&nbsp;&nbsp; -RoB</FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0019_01BD42CB.61337B00--

- Raw text -


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