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



Relevant Pages

  • Help needed in solving C-errors in Linux (gcc)
    ... i'm trying to make I got the following messages from gcc. ... main.c:22: warning: comparison is always false due to limited range of data type ... int conv_inch2feet; ... int convert(int unit, const char *,const char *,const char *); ...
    (comp.os.linux.development.apps)
  • Help needed in solving C-errors in Linux (gcc)
    ... i'm trying to make I got the following messages from gcc. ... main.c:22: warning: comparison is always false due to limited range of data type ... int conv_inch2feet; ... int convert(int unit, const char *,const char *,const char *); ...
    (alt.os.linux)
  • Re: static array size: int foo[static 2]
    ... GCC does accept it as legal. ... int read(int fd, const char buf, unsigned count) ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Re: Invalid operands to binary -
    ... int main{ ... const char **p2; ... When I try to compile the above on gcc 4.1.2 I get ...
    (comp.lang.c)
  • Re: data types
    ... Usually short is smaller than an int. ... Your compiler is either *really* old or broken or both. ... recommend either a version of gcc,, or Visual Studio ... Microsoft's Visual Studio Express has an onerous EULA). ...
    (comp.lang.c)