Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strncpy(3) — NEWS-os 4.2.1R

Media Vault

Software Library

Restoration Projects

Artifacts Sought

STRING(3)  —  NEWS-OS Programmer’s Manual

NAME

strcat, strncat, strcmp, strncmp, strcasecmp, strncasecmp, strcpy, strncpy, strlen, index, rindex, strchr, strrchr, strpbrk, strspn, strcspn, strtok, strstr, strdup  − string operations

SYNOPSIS

#include <string.h>

char ∗strcat(s1, s2)
char ∗s1, ∗s2;

char ∗strncat(s1, s2, n)
char ∗s1, ∗s2;
int n;

strcmp(s1, s2)
char ∗s1, ∗s2;

strncmp(s1, s2, n)
char ∗s1, ∗s2;
int n;

strcasecmp(s1, s2)
char ∗s1, ∗s2;

strncasecmp(s1, s2, n)
char ∗s1, ∗s2;
int n;

char ∗strcpy(s1, s2)
char ∗s1, ∗s2;

char ∗strncpy(s1, s2, n)
char ∗s1, ∗s2;
int n;

strlen(s)
char ∗s;

char ∗index(s, c)
char ∗s, c;

char ∗rindex(s, c)
char ∗s, c;

char ∗strchr(s, c)
char ∗s;
int c;

char ∗strrchr(s, c)
char ∗s;
int c;

char ∗strpbrk(s1, s2)
char ∗s1, ∗s2;

int strspn(s1, s2)
char ∗s1, ∗s2;

int strcspn(s1, s2)
char ∗s1, ∗s2;

char ∗strtok(s1, s2)
char ∗s1, ∗s2;

char ∗strstr(s1, s2)
char ∗s1, ∗s2;

char ∗strdup(s)
char ∗s;

DESCRIPTION

These functions operate on null-terminated strings.  They do not check for overflow of any receiving strings. 

strcat appends a copy of string s2 to the end of string s1. strncat copies at most n characters.  Both functions return a pointer to the null-terminated result. 

strcmp compares its arguments (both interpreted as unsigned char strings) and returns an integer greater than, equal to, or less than 0, according as s1 is lexicographically greater than, equal to, or less than s2. strncmp makes the same comparison but looks at at most n characters. 

strcasecmp and strncasecmp are identical in function, but are case insensitive.  The returned lexicographic difference reflects a conversion to lower-case. 

strcpy copies string s2 to s1, stopping after the null character has been moved. strncpy copies exactly n characters, truncating or null-padding s2; the target may not be null-terminated if the length of s2 is n or more.  Both functions return s1.

strlen returns the number of characters in s, not including the terminating null character.

index (rindex) returns a pointer to the first (last) occurrence of character c in string s, or NULL pointer if c does not occur in the string.  The null character terminating a string is considered to be part of the string. 

strchr (strrchr) is the same function with index (rindex), having the different name. 

strpbrk returns a pointer to the first occurrence in string s1 of any character from string s2, or a NULL pointer if no character from s2 exists in s1.

strspn (strcspn) returns the length of the initial segment of string s1 which consists entirely of characters from (not from) string s2.

strtok considers the string s1 to consist of a sequence of zero or more text tokens separated by spans of one or more characters from the separator string s2. The first call (with pointer s1 specified) returns a pointer to the first character of the first token, and will have written a NULL character into s1 immediately following the returned token.  The function keeps track of its position in the string between separate calls, so that subsequent calls (which must be made with the first argument a NULL pointer) will work through the string s1 immediately following that token.  In this way subsequent calls will work through the string s1, returning a pointer to the first character of each subsequent token. A null character will have been written into s1 by strtok immediately following the token.  The separator string s2 may be different from call to call.  When no token remains in s1, a NULL pointer is returned.

strstr returns a pointer to the first occurrence of string s2 in string s1, or NULL pointer if s2 does not occur in the string. 

strdup returns a pointer to a new string which is a duplicate of the string s1. The space for the new string is obtained using malloc(3).  If the new string cannot be created, a NULL pointer is returned. 

CAUTIONS

1Both strcmp and strncmp may not work correctly on other machines since their implementations depend on each machine. 

2A NULL pointer should not be used instead of a null string because in the C language a NULL pointer would not always indicate a null string. 

3Character movement functions also depend on implementations.  Therefore overlapping moves may cause unexpected results. 

NEWS-OSRelease 4.2.1R

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