Mail Archives: djgpp/2002/02/24/06:24:14
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f
|
Message-ID: | <006f01c1bd25$839675c0$088f6518@mtww.phub.net.cable.rogers.com>
|
From: | "Bill Henderson" <inconnu AT softhome DOT net>
|
To: | djgpp AT delorie DOT com
|
Subject: | String Problems
|
Date: | Sun, 24 Feb 2002 06:21:36 -0500
|
MIME-Version: | 1.0
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Mailer: | Microsoft Outlook Express 5.50.4807.1700
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4807.1700
|
Reply-To: | djgpp AT delorie DOT com
|
This is a multi-part message in MIME format.
------=_NextPart_000_006A_01C1BCFB.831E51A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
System:
Compaq DeskPro 133 (Overclocked to 167)
64 Meg Ram
Windows 95 (Version 4.0.1111)
Redhat 7.2 Linux
3 GB Maxtor hda/c: drive
30 GB El Cheapo as hdb
(Remember the LameBrain Compaq BIOS can't see hdb so the d: drive in =
DOS-Speak is the CD Drive)
3Com 3C509B NIC
Terayon Cable Modem
The only other non-system/non Windoze stuff loaded when I use DJGPP is a =
firewall, a siren for the same, ON-Track Real Time Virus Scanner, and =
MSN.
I downloaded and installed DJGPP without problem.
Firing up RHide, everything worked A-OK the first time, greeting the =
World with no problem at all.
But on trying to produce something non-trivial, the lack of string =
handling functions in libc seems to be a limiting function.
I decided to produce a comprehensive password listing, referred to by =
some miscreants as a cracklist. And as you will appreciate, testing the =
results has to be done using math to verify file numbers and file =
positions. (A Four character password listing, if one includes single, =
double and triple characters as well produces 15,783 files if one stores =
5000 records per file.)
Consequently it was some time before I discovered the problem, and it =
still only became evident when I noticed that some of the files were =
smaller than their neighbours. Specifically the ones which should have =
contained significant numbers of percent characters.
Now I haven't used C for some 20 years and may be a little rusty, BUT:
I produced the following code snippet to illustrate the problem so:
(1) Why will the following code output to the screen perfectly (with the =
percent symbol output correctly either escaped or not), whilst it is =
impossible to place the percent character into a file which produces:
1
[nothing in the file except the newline]
[nothing in the file except the newline]
2
\
3
"
4
(2) Is it really necessary to use arrays to satisfactorily manipulate =
strings?
(3) I notice getchar() misbehaving and, although I didn't replicate the =
situation in the code below, I have had to clear the buffer with extra, =
and to my way of thinking, unnecessary, throw_away_int =3D getchar() =
calls. I had thought getchar() was echoed and buffered, and a peak at an =
old manual confirms this? Am I missing something here?
Unfortunately I was a couple of days into the project before I tried =
writing a file and had up to then been happily dumping fragments of it =
to the CRT where it looked as though everything was going as intended.
{START CODE]
/* test */
#include <stdio.h>
int main()
{
char lf[2] =3D { '\n' } ;
int i =3D 0 ;
char ch[8][2] =3D { "1", "%", "\%", "2", "\\", "3", "\"", "4" } ;
FILE *fp ;
fp =3D fopen( "file1.lst", "w" ) ;
for ( i =3D 0 ; i < 8 ; i++ )
{
printf( "\ncharacter %n =3D=3D %s ", i, ch[i] ) ;
fprintf( fp, ch[i] ) ;
fprintf( fp, lf ) ;
}
fclose( fp ) ;
return( 0 ) ;
}
{END CODE]
Thanks,
Bill Henderson
------=_NextPart_000_006A_01C1BCFB.831E51A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4807.2300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>System:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Compaq DeskPro 133 (Overclocked to=20
167)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>64 Meg Ram</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Windows 95 (Version =
4.0.1111)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Redhat 7.2 Linux</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>3 GB Maxtor hda/c: drive</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>30 GB El Cheapo as hdb</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>(Remember the LameBrain Compaq BIOS =
can't see hdb=20
so the d: drive in DOS-Speak is the CD Drive)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>3Com 3C509B NIC</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Terayon Cable Modem</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The only other non-system/non Windoze =
stuff loaded=20
when I use DJGPP is a firewall, a siren for the same, ON-Track Real Time =
Virus=20
Scanner, and MSN.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I downloaded and installed DJGPP =
without=20
problem.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Firing up RHide, everything worked A-OK =
the first=20
time, greeting the World with no problem at all.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>But on trying to produce something =
non-trivial, the=20
lack of string handling functions in libc seems to be a limiting=20
function.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I decided to produce a comprehensive =
password=20
listing, referred to by some miscreants as a cracklist. And as you will=20
appreciate, testing the results has to be done using math to verify file =
numbers=20
and file positions. (A Four character password listing, if one =
includes=20
single, double and triple characters as well produces 15,783 files if =
one stores=20
5000 records per file.)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Consequently it was some time before I =
discovered=20
the problem, and it still only became evident when I noticed that some =
of the=20
files were smaller than their neighbours. Specifically the ones which =
should=20
have contained significant numbers of percent characters.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Now I haven't used C for some 20 years =
and may be a=20
little rusty, BUT:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I produced the following code snippet =
to illustrate=20
the problem so:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>(1) Why will the following code output =
to the=20
screen perfectly (with the percent symbol output correctly either =
escaped or=20
not), whilst it is impossible to place the percent character into a file =
which=20
produces:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>[nothing in the file except the=20
newline]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>[nothing in the file except the=20
newline]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>2</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>\</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>3</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>"</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>4</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT size=3D2><FONT face=3DArial>(2) Is it really necessary to use =
arrays to=20
satisfactorily manipulate strings?</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>(3) I notice getchar() misbehaving and, =
although I=20
didn't replicate the situation in the code below, I have had to clear =
the buffer=20
with extra, and to my way of thinking, unnecessary, throw_away_int =3D =
getchar()=20
calls. I had thought getchar() was echoed and buffered, and a peak at an =
old=20
manual confirms this? Am I missing something here?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Unfortunately I was a couple of days =
into the=20
project before I tried writing a file and had up to then been happily =
dumping=20
fragments of it to the CRT where it looked as though everything was =
going as=20
intended.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT size=3D2><FONT face=3DArial></FONT></FONT> </DIV>
<DIV><FONT size=3D2><FONT face=3DArial>{START CODE]</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial><FONT face=3D"Courier New" =
size=3D2>
<P>/* test */</P>
<P>#include <stdio.h></P>
<P>int main()</P>
<P>{</P>
<P>char lf[2] =3D { '\n' } ;</P>
<P>int i =3D 0 ;</P>
<P>char ch[8][2] =3D { "1", "%", "\%", "2", "\\", "3", "\"", "4" } ;</P>
<P>FILE *fp ;</P>
<P>fp =3D fopen( "file1.lst", "w" ) ;</P>
<P>for ( i =3D 0 ; i < 8 ; i++ )</P>
<P>{</P>
<P>printf( "\ncharacter %n =3D=3D %s ", i, ch[i] ) ;</P>
<P>fprintf( fp, ch[i] ) ;</P>
<P>fprintf( fp, lf ) ;</P>
<P>}</P>
<P>fclose( fp ) ;</P>
<P>return( 0 ) ;</P>
<P>}</P></FONT></FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial>{END CODE]</FONT></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Bill =
Henderson</FONT></DIV></BODY></HTML>
------=_NextPart_000_006A_01C1BCFB.831E51A0--
- Raw text -