Re: crypt function

From: jenuths@homacjen.ab.ca
Date: 03/25/02


From: jenuths@homacjen.ab.ca
Date: Mon, 25 Mar 2002 13:56:04 GMT

dwij <dwijaggarwal@yahoo.com> wrote:

When you use gcc, are you forgetting to include the crypt library

gcc -lcrypt blog.c

> hello
> i am receiving an error undefined reference to crypt i am enclosing the full code:

> #include <stdio.h>
> #include <time.h>
> #include <unistd.h>
> #include <crypt.h>

> int
> main(void)
> {
> unsigned long seed[2];
> char salt[] = "$1$........";
> const char *const seedchars =
> "./0123456789ABCDEFGHIJKLMNOPQRST"
> "UVWXYZabcdefghijklmnopqrstuvwxyz";
> char *password;
> int i;
>
> /* Generate a (not very) random seed.
> You should do it better than this... */
> seed[0] = time(NULL);
> seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
>
> /* Turn it into printable characters from `seedchars'. */
> for (i = 0; i < 8; i++)
> salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
>
> /* Read in the user's password and encrypt it. */
> password = crypt(getpass("Password:"), salt);
>
> /* Print the results. */
> puts(password);
> return 0;
> }

> this code gives me the error : undefined reference to crypt
> i am using redhat 7.1
> dwij

-- 

Best regards,

Stephen Jenuth (jenuths@homacjen.ab.ca)

Quidquid latine dictum sit, altum viditur.

pgp/gpg public key available at http://keyserver.pgp.com