-->

Previous | Table of Contents | Next

Page 952

RETURN VALUE

hcreate() returns NULL if the hash table cannot be successfully installed.

hsearch()returns NULL if action is ENTER and there is insufficient memory to expand the hash table, or if action is FIND and item cannot be found in the hash table.

CONFORMS TO

SVID, except that in SysV, the hash table cannot grow.

BUGS

The implementation can manage only one hash table at a time. Individual hash table entries can be added, but not deleted.

EXAMPLE

The following program inserts 24 items into a hash table and then prints some of them:


#include <stdio.h>

#include <search.h>

char *data[]={ "alpha", "bravo", "charley", "delta",

  "echo", "foxtrot", "golf", "hotel", "india", "juliette",

  "kilo", "lima", "mike", "november", "oscar", "papa",

  "quebec", "romeo", "sierra", "tango", "uniform",

  "victor", "whiskey", "x-ray", "yankee", "zulu"

};

int main()

{

  ENTRY e, *ep;

  int i;

  /* start with small table, and let it grow */

  hcreate(3);

  for (i = 0; i < 24; i++)

  {

    e.key = data[i];

    /* data is just an integer, instead of a pointer

      to something */

    e.data = (char *)i;

    ep = hsearch(e, ENTER);

    /* there should be no failures */

    if(ep == NULL) {fprintf(stderr, "entry failed\n"); exit(1);}

  }

  for (i = 22; i < 26; i++)

    /* print two entries from the table, and show that

      two are not in the table */

  {

  e.key = data[i];

  ep = hsearch(e, FIND);

  printf("%9.9s -> %9.9s:%d\n", e.key, ep?ep->key:"NULL",

    ep?(int)(ep->data):0);

  }

  return 0;

}

SEE ALSO

bsearch(3), lsearch(3), tsearch(3), malloc(3)

GNU, 30 September 1995

Page 953

hypot

hypot—Euclidean distance function

SYNOPSIS


#include <math.h>

double hypot(double x, double y);

DESCRIPTION

The hypot() function returns the sqrt(x*x+y*y). This is the length of the hypotenuse of a right-angle triangle with sides of length x and y, or the distance of the point (x, y) from the origin.

CONFORMS TO

SVID 3, BSD 4.3

SEE ALSO

sqrt(3)

25 June 1993

index, rindex

index, rindex—Locate character in string

SYNOPSIS


#include <string.h>

char *index(const char *s,int c);

char *rindex(const char *s,int c);

DESCRIPTION

The index() function returns a pointer to the first occurrence of the character c in the string s.

The rindex() function returns a pointer to the last occurrence of the character c in the string s.

The terminating NULL character is considered to be a part of the strings.

RETURN VALUE

The index() and rindex() functions return a pointer to the matched character, or NULL if the character is not found.

CONFORMS TO

BSD 4.3

SEE ALSO

memchr(3), strchr(3), strpbrk(3), strrchr(3), strsep(3), strspn(3), strstr(3), strtok(3)

GNU, 12 April 1993

inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr,
inet_lnaof, inet_netof

inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof, inet_netof—Internet address_manipulation routines

Page 954

SYNOPSIS


#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

int inet_aton(const char *cp, struct in_addr *inp);

unsigned long int inet_addr(const char *cp);

unsigned long int inet_network(const char *cp);

char *inet_ntoa(struct in_addr in);

struct in_addr inet_makeaddr(int net, int host);

unsigned long int inet_lnaof(struct in_addr in);

unsigned long int inet_netof(struct in_addr in);

DESCRIPTION

inet_aton() converts the Internet host address cp from the standard numbers-and-dots notation into binary data and stores it in the structure that inp points to. inet_aton returns nonzero if the address is valid, and 0 if it is not.

The inet_addr()function converts the Internet host address cp from numbers-and-dots notation into binary data in network byte order. If the input is invalid, _1 is returned. This is an obsolete interface to inet_aton; it is obsolete because -1 is a valid address (255.255.255.255), and inet_aton provides a cleaner way to indicate error return.

The inet_network() function extracts the network number in network byte order from the address cp in numbers-and-dots notation. If the input is invalid, _1 is returned.

The inet_ntoa() function converts the Internet host address given in network byte order to a string in standard numbers-and-dots notation. The string is returned in a statically allocated buffer, which subsequent calls will overwrite.

The inet_makeaddr() function makes an Internet host address in network byte order by combining the network number net with the local address host in network net, both in local host byte order.

The inet_lnaof() function returns the local host address part of the Internet address in. The local host address is returned in local host byte order.

The inet_netof()function returns the network number part of the Internet address in. The network number is returned in local host byte order.

The structure in_addr as used in inet_ntoa(), inet_makeaddr(), inet_lnoaf(), and inet_netof() is defined in netinet/in.h as


struct in_addr {

unsigned long int s_addr;

}

Note that on the i80x86 the host byte order is Least Significant Byte first, whereas the network byte order, as used on the Internet, is Most Significant Byte first.

CONFORMS TO

BSD 4.3

SEE ALSO

gethostbyname(3), getnetent(3), hosts(5), networks(5)

BSD, 3 September 1995

infnan

infnan—Deals with infinite or not-a-number (NaN) result

SYNOPSIS


#include <math.h>

double infnan(int error);

Previous | Table of Contents | Next