From: "RoB" 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 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0019_01BD42CB.61337B00" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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
i was = writing a cpp=20 program.  in this program i marked a variable = as: 
 
char* = data 
 
i = then made this a=20 string of [30]:
 
{
size =3D=20 strlen(init);
data =3D new char[size + 1];
assert(data !=3D 0);
strcpy(data, init); 
}
 
where = "init" was just nothing  ""  ... i'm just=20 initializing here... 
 
okay then i entered into the new = array i a name=20 just a buncha characters from instream:
my input operator = looks like=20 this:
{
    char=20 c;
    int nws;
    int i =3D 0;
   
    do=20 {
        c =3D=20 cin.peek();
        if (c =3D=3D ' = ' || c =3D=3D=20 '\n' || c =3D=3D '\t' || c =3D=3D '\r') {
       =20 cin.get();         // checking = for white=20 space
        nws =3D=20 0;
        = }
        = else
         &nbs= p; =20 nws =3D 1;
    } while (nws =3D=3D = 0);
 
    while=20 (i < string::max && input.peek() !=3D '\n') {  // = getting=20 string... until
         &nbs= p;            = ;            =             &= nbsp;       =20 // control  "/n"
        = right.data[i++] =3D=20 input.get();          &= nbsp;     =20 // or whatever  "/@$#!@#%" ...
   =20 }
 
   =20 right.data[i] =3D '\0';  // making the last element in the array=20 "\0"
    cin.ignore();   // getting = rid of the=20 control
    return input;   // blah=20 blah...
}
 
i know this seems = very=20 cumbersome.  but, this is the way i had to do it...
 
 
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...
 
my output command is=20 this:
 
{
output << = right.data;  // where=20 right.data is of type specified above...
return = output; 
}
 
so am i doing something wrong = in my code or=20 is this something about djgpp i have to configure?
 
btw: this works on sun solaris = @=20 school...  i get correct output...
 
grassyass...
 
plz respond to:
 
      =20 ,-~~-.___.
      / |  = '    =20 \       The words of the prophets are=20 not
     ( =20 )        =20 0      as sweet as the beat of the=20 drums
      \_/-,=20 ,----'       in the souls of our=20 feet.
        =20 =3D=3D=3D=3D           = //
        /  = \-'~;   =20 /~~~(O)           =        =20 \,`/ /
       /  __/~|   = /      =20 |            =      =20 _)..  `-
     =3D(  _____|=20 (_________|          &n= bsp;     =20 ( __  -\
  =20 +=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D   = ;            =  =20 '`.
   | rel8ivity AT erols DOT com  &n= bsp;  =20 |            =    =20 ( \>_-_,
  =20 =3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+=3D+   = ;            = =20 _||_ ~-/    -RoB
 
------=_NextPart_000_0019_01BD42CB.61337B00--