Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

string(3)

strcasecmp(3)

strcat(3)

strcmp(3)

strcpy(3)

wcsncat(3)

wcsncmp(3)

wcsncpy(3)

strncat(3)  —  Subroutines

NAME

strncasecmp, strncat, strncmp, strncpy − Perform operations on string

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <string.h> char ∗strncasecmp(
const char ∗s1,
const char ∗s2
size_t n); char ∗strncat(
char ∗s1,
const char ∗s2,
size_t n); int strncmp(
const char ∗s1,
const char ∗s2,
size_t n); char ∗strncpy(
char ∗s1,
const char ∗s2,
size_t n);

PARAMETERS

s1Points to a location containing first string. 

s2Points to a location containing the second of two strings referenced. 

nSpecifies the number of bytes in a string.  In strncat(), n specifies the maximum number of bytes to append; in strncmp() and strncasecmp(), n specifies the maximum number of bytes to compare; and in strncpy(), n specifies the number of bytes to copy. 

DESCRIPTION

The strncat() function appends n bytes in the string pointed to by the s2 parameter to the end of the string pointed to by the s1 parameter. The initial character of the string pointed to by s2 overwrites the null character at the end of the string pointed to by s1.  The strncat() function appends at most the number of characters specified by the value of the n parameter minus 1.  It then appends a null byte to the result, and returns s1.  When operating on overlapping strings, the behavior of this function is unreliable. 

The strncmp() function compares the string pointed to by the s1 parameter to the string pointed to by the s2 parameter.  The sign of a nonzero value returned by strcmp() is determined by the sign of the difference between the values of the first pair of bytes (both interpreted as unsigned char) that differ in the two compared objects. The strncmp() functions compares bytes until it has compared n bytes or until it reaches a terminating null byte. 

The strncmp() function compares strings based on the machine collating order. It does not use the locale-dependent sorting order.  Use the strcol() or wcscol() functions for locale-dependent sorting. 

and strncasecmp() function is case insensitive. The returned lexicographic difference reflects a conversion to lower case.  The strncasecmp() function is similar to the strcasecmp function, but also compares size. If the size specified by n is reached before a null, the comparison stops.  Note that strncasecmp() works for 7-bit ASCII compares only and should not be used in internationalized applications. 

The strncpy() function copies no more than the number of characters specified by the n parameter from the location pointed to by the s2 parameter to the location pointed to by the s1 parameter.  Characters following a null character are not copied.  When operating on overlapping strings, the behavior of this function is unreliable.  When the location pointed to by the s2 parameter is a string whose character length is less than the value specified by the n parameter, null characters are appended to the s1 string until n characters are contained in the string. 

NOTES

AES Support Level:
Full use (strncat(), strncmp(), strncpy()). 

RETURN VALUES

Upon successful completion, the strncat() and strncpy() functions return a pointer to the resulting string. Otherwise, these functions return a null pointer. 

Upon successful completion, the strncmp() and strncasecmp() functions return an integer whose value is greater than, equal to, or less than 0 (zero), according to whether the s1 string is greater than, equal to, or less than the s2 string. When a successful comparison cannot be made, these functions return a value of 0 (zero). 

RELATED INFORMATION

Functions: string(3), strcasecmp(3), strcat(3), strcmp(3), strcpy(3), wcsncat(3), wcsncmp(3), wcsncpy(3). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026