COHERENT manpages
This page displays the COHERENT manpage for string.h [Declarations for string library].
List of available manpages
Index
string.h -- Header File Declarations for string library #include <string.h> string.h is the header that holds the prototypes of all ANSI routines that handle strings and buffers. It declares the following routines: fnmatch()......Match a string with a normal expression index()........Search string for a character; use strchr() instead memccpy()......Copy a region of memory up to a set character memchr().......Search a region of memory for a character memcmp().......Compare two regions of memory memcpy().......Copy one region of memory into another memmove()......Copy one region of memory into another with which it overlaps memset().......Fill a region of memory with a character pnmatch()......Match string pattern strcat().......Concatenate two strings strcmp().......Compare two strings strncat()......Append one string onto another strncmp()......Compare two lengths for a set number of bytes strcpy().......Copy a string strncpy()......Copy a portion of a string strcoll()......Compare two strings, using locale information strcspn()......Return length one string excludes characters in another strdup().......Duplicate a string strerror().....Translate an error number into a string strlen().......Measure a string strpbrk()......Find first occurrence in string of character from another string strchr().......Find leftmost occurrence of character in a string strrchr()......Find rightmost occurrence of character in a string strspn().......Return length one string includes character in another strstr().......Find one string within another string strtok().......Break a string into tokens strxfrm()......Transform a string, using locale information Example This example reads from stdin up to NNAMES names, each of which is no more than MAXLEN characters long. It then removes duplicate names, sorts the names, and writes the sorted list to the standard output. It demonstrates the functions shellsort(), strcat(), strcmp(), strcpy(), and strlen(). #include <stdio.h> #include <stdlib.h> #include <string.h> #define NNAMES 512 #define MAXLEN 60 char *array[NNAMES]; char first[MAXLEN], mid[MAXLEN], last[MAXLEN]; char *space = " "; int compare(); main() { register int index, count, inflag; register char *name; count = 0; while (scanf("%s %s %s\n", first, mid, last) == 3) { strcat(first, space); strcat(mid, space); name = strcat(first, (strcat(mid, last))); inflag = 0; for (index=0; index < count; index++) if (strcmp(array[index], name) == 0) inflag = 1; if (inflag == 0) { if ((array[count] = malloc(strlen(name) + 1)) == NULL) { fprintf(stderr, "Insufficient memory\n"); exit(EXIT_FAILURE); } strcpy(array[count], name); count++; } } shellsort(array, count, sizeof(char *), compare); for (index=0; index < count; index++) printf("%s\n", array[index]); exit(EXIT_SUCCESS); } compare(s1, s2) register char **s1, **s2; { return(strcmp(*s1, *s2)); } See Also header files, libc, strcasecmp(), strcasencmp() ANSI Standard, §7.1.1 Notes Some implementations of UNIX call this header file strings.h. If you are porting code to COHERENT, you may have to modify the #include directives that invoke this header file. The ANSI standard allows adjacent string literals, e.g.: "hello" "world" Adjacent string literals are automatically concatenated. Thus, the compiler will automatically concatenate the above example into: "helloworld" Because this departs from the Kernighan and Ritchie description of C, it will generate a warning message if you use the compiler's -VSBOOK option.