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" To: djgpp AT delorie DOT com Subject: String Problems Date: Sun, 24 Feb 2002 06:21:36 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_006A_01C1BCFB.831E51A0" 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 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
System:
Compaq DeskPro 133 (Overclocked to=20 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=20 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=20 when I use DJGPP is a firewall, a siren for the same, ON-Track Real Time = Virus=20 Scanner, and MSN.
 
I downloaded and installed DJGPP = without=20 problem.
 
Firing up RHide, everything worked A-OK = the first=20 time, greeting the World with no problem at all.
 
But on trying to produce something = non-trivial, the=20 lack of string handling functions in libc seems to be a limiting=20 function.
 
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.)
 
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.
 
Now I haven't used C for some 20 years = and may be a=20 little rusty, BUT:
 
I produced the following code snippet = to illustrate=20 the problem so:
 
(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:
 
1
[nothing in the file except the=20 newline]
[nothing in the file except the=20 newline]
2
\
3
"
4
 
(2) Is it really necessary to use = arrays to=20 satisfactorily manipulate strings?
 
(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?
 
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.
 
 
{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--