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. in this program i marked a variable =
as:</FONT></FONT><FONT=20
face=3DCourier></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT face=3DCourier>char* =
data</FONT></FONT><FONT face=3DCourier></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT> </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> </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> </DIV>
<DIV><FONT face=3DCourier size=3D2>}</FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT=20
face=3DCourier></FONT></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT face=3DCourier>where =
"init" was just nothing "" ... i'm just=20
initializing here...</FONT></FONT><FONT =
face=3DCourier></FONT> </DIV>
<DIV> </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> char=20
c;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> int nws;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> 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> </FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier> do=20
{</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> c =3D=20
cin.peek();</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> 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> =20
cin.get(); // checking =
for white=20
space</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> 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> =
}</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> =
else</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> &nbs=
p; =20
nws =3D 1;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> } 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> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier> while=20
(i < string::max && input.peek() !=3D '\n') { // =
getting=20
string... until</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT=20
face=3DCourier> &nbs=
p;  =
; =
&=
nbsp; =20
// control "/n"</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT=20
face=3DCourier> =
right.data[i++] =3D=20
input.get(); &=
nbsp; =20
// or whatever "/@$#!@#%" ...</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> =20
}</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier></FONT></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier> =20
right.data[i] =3D '\0'; // making the last element in the array=20
"\0"</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><FONT =
face=3DCourier></FONT><FONT=20
face=3DCourier> cin.ignore(); // 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> return input; // 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> </DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>i know this seems =
very=20
cumbersome. but, this is the way i had to do it...</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>okay, the problem =
lies in the=20
output! when i print the output to output stream (stdout or =
file) 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> </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> </DIV>
<DIV><FONT color=3D#000000 face=3DCourier size=3D2>{</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>output << =
right.data; // where=20
right.data is of type specified above...</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>return =
output;</FONT> </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> </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> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>btw: this works on sun solaris =
@=20
school... i get correct output...</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier>grassyass...</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>plz respond to:</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2> =20
,-~~-.___.<BR> / | =
' =20
\ The words of the prophets are=20
not<BR> ( =20
) =20
0 as sweet as the beat of the=20
drums<BR> \_/-,=20
,----' in the souls of our=20
feet.<BR> =20
=3D=3D=3D=3D =
//<BR> / =
\-'~; =20
/~~~(O) =
=20
\,`/ /<BR> / __/~| =
/ =20
| =
=20
_).. `-<BR> =3D( _____|=20
(_________| &n=
bsp; =20
( __ -\<BR> =20
+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D  =
; =
=20
'`.<BR> | <A=20
href=3D"mailto:rel8ivity AT erols DOT com">rel8ivity AT erols DOT com</A> &n=
bsp; =20
| =
=20
( \>_-_,<BR> =20
=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+  =
; =
=20
_||_ ~-/ -RoB</FONT> </DIV></BODY></HTML>
------=_NextPart_000_0019_01BD42CB.61337B00--
- Raw text -