B
BMarsh
Hi all,
I have a slight problem understanding the following code that I saw on
a Unix-PAM tutorial (not OT!)
The following code will compare and old string to a new one, bombing
out if 'max' similar chars is exceeded.
------8<------
static
int compare(unsigned char *old, unsigned char *new, int max)
{
unsigned char in_old[256];
int equal = 0;
(void)memset(in_old, 0, sizeof (in_old));
while (*old)
in_old[*(old++)]++;
while (*new) {
if (in_old[*new])
equal++;
new++;
}
if (equal > max)
return (1);
return (0);
}
------->8---------
I fail to see how the 2 strings are compared for character equality,
especially in how the
in_old[*(old++)]++;
line is used.
Could anyone please shed some light on this for me?
cheers
Bry
I have a slight problem understanding the following code that I saw on
a Unix-PAM tutorial (not OT!)
The following code will compare and old string to a new one, bombing
out if 'max' similar chars is exceeded.
------8<------
static
int compare(unsigned char *old, unsigned char *new, int max)
{
unsigned char in_old[256];
int equal = 0;
(void)memset(in_old, 0, sizeof (in_old));
while (*old)
in_old[*(old++)]++;
while (*new) {
if (in_old[*new])
equal++;
new++;
}
if (equal > max)
return (1);
return (0);
}
------->8---------
I fail to see how the 2 strings are compared for character equality,
especially in how the
in_old[*(old++)]++;
line is used.
Could anyone please shed some light on this for me?
cheers
Bry