C Standard Library: 3 String Functions: <string.h>
2013-03-21 11:17
405 查看
3 String Functions: <string.h>
There are two groups of string functions defined in the header <string.h>. The first have
names beginning with str; the second have names beginning with mem. Except for memmove,
the behavior is undefined if copying takes place between overlapping objects. Comparison
functions treat arguments as unsigned char arrays.
In the following table, variables s and t are of type char *; cs and ct are of type const char
*; n is of type size_t; and c is an int converted to char.
char *strcpy(s,ct) copy string ct to string s, including '\0'; return s.
char *strncpy(s,ct,n)
copy at most n characters of string ct to s; return s. Pad with '\0''s
if ct has fewer than n characters.
char *strcat(s,ct) concatenate string ct to end of string s; return s.
char *strncat(s,ct,n)
concatenate at most n characters of string ct to string s, terminate s
with '\0'; return s.
int strcmp(cs,ct) compare string cs to string ct, return <0 if cs<ct, 0 if cs==ct, or >0
if cs>ct.
int strncmp(cs,ct,n)
compare at most n characters of string cs to string ct; return <0 if
cs<ct, 0 if cs==ct, or >0 if cs>ct.
char *strchr(cs,c) return pointer to first occurrence of c in cs or NULL if not present.
char *strrchr(cs,c) return pointer to last occurrence of c in cs or NULL if not present.
size_t strspn(cs,ct) return length of prefix of cs consisting of characters in ct.
size_t strcspn(cs,ct) return length of prefix of cs consisting of characters not in ct.
char *strpbrk(cs,ct) return pointer to first occurrence in string cs of any character string
ct, or NULL if not present.
char *strstr(cs,ct) return pointer to first occurrence of string ct in cs, or NULL if not
present.
size_t strlen(cs) return length of cs.
char *strerror(n) return pointer to implementation-defined string corresponding to
error n.
char *strtok(s,ct)
strtok searches s for tokens delimited by characters from ct; see
below.
A sequence of calls of strtok(s,ct) splits s into tokens, each delimited by a character from
ct. The first call in a sequence has a non-NULL s, it finds the first token in s consisting of
characters not in ct; it terminates that by overwriting the next character of s with '\0' and
returns a pointer to the token. Each subsequent call, indicated by a NULL value of s, returns the
next such token, searching from just past the end of the previous one. strtok returns NULL
when no further token is found. The string ct may be different on each call.
The mem... functions are meant for manipulating objects as character arrays; the intent is an
interface to efficient routines. In the following table, s and t are of type void *; cs and ct are
of type const void *; n is of type size_t; and c is an int converted to an unsigned char.
void *memcpy(s,ct,n) copy n characters from ct to s, and return s.
void *memmove(s,ct,n) same as memcpy except that it works even if the objects overlap.
int memcmp(cs,ct,n) compare the first n characters of cs with ct; return as with strcmp.
void *memchr(cs,c,n) return pointer to first occurrence of character c in cs, or NULL if not
present among the first n characters.
void *memset(s,c,n) place character c into first n characters of s, return s.
There are two groups of string functions defined in the header <string.h>. The first have
names beginning with str; the second have names beginning with mem. Except for memmove,
the behavior is undefined if copying takes place between overlapping objects. Comparison
functions treat arguments as unsigned char arrays.
In the following table, variables s and t are of type char *; cs and ct are of type const char
*; n is of type size_t; and c is an int converted to char.
char *strcpy(s,ct) copy string ct to string s, including '\0'; return s.
char *strncpy(s,ct,n)
copy at most n characters of string ct to s; return s. Pad with '\0''s
if ct has fewer than n characters.
char *strcat(s,ct) concatenate string ct to end of string s; return s.
char *strncat(s,ct,n)
concatenate at most n characters of string ct to string s, terminate s
with '\0'; return s.
int strcmp(cs,ct) compare string cs to string ct, return <0 if cs<ct, 0 if cs==ct, or >0
if cs>ct.
int strncmp(cs,ct,n)
compare at most n characters of string cs to string ct; return <0 if
cs<ct, 0 if cs==ct, or >0 if cs>ct.
char *strchr(cs,c) return pointer to first occurrence of c in cs or NULL if not present.
char *strrchr(cs,c) return pointer to last occurrence of c in cs or NULL if not present.
size_t strspn(cs,ct) return length of prefix of cs consisting of characters in ct.
size_t strcspn(cs,ct) return length of prefix of cs consisting of characters not in ct.
char *strpbrk(cs,ct) return pointer to first occurrence in string cs of any character string
ct, or NULL if not present.
char *strstr(cs,ct) return pointer to first occurrence of string ct in cs, or NULL if not
present.
size_t strlen(cs) return length of cs.
char *strerror(n) return pointer to implementation-defined string corresponding to
error n.
char *strtok(s,ct)
strtok searches s for tokens delimited by characters from ct; see
below.
A sequence of calls of strtok(s,ct) splits s into tokens, each delimited by a character from
ct. The first call in a sequence has a non-NULL s, it finds the first token in s consisting of
characters not in ct; it terminates that by overwriting the next character of s with '\0' and
returns a pointer to the token. Each subsequent call, indicated by a NULL value of s, returns the
next such token, searching from just past the end of the previous one. strtok returns NULL
when no further token is found. The string ct may be different on each call.
The mem... functions are meant for manipulating objects as character arrays; the intent is an
interface to efficient routines. In the following table, s and t are of type void *; cs and ct are
of type const void *; n is of type size_t; and c is an int converted to an unsigned char.
void *memcpy(s,ct,n) copy n characters from ct to s, and return s.
void *memmove(s,ct,n) same as memcpy except that it works even if the objects overlap.
int memcmp(cs,ct,n) compare the first n characters of cs with ct; return as with strcmp.
void *memchr(cs,c,n) return pointer to first occurrence of character c in cs, or NULL if not
present among the first n characters.
void *memset(s,c,n) place character c into first n characters of s, return s.
相关文章推荐
- standard c library <string.h>
- C/C++ standard library -- <cstring>(string.h)
- C Standard Library: 2 Character Class Tests: <ctype.h>
- C Standard Library: 6 Diagnostics: <assert.h>
- C Standard Library: 11 Implementation-defined Limits: <limits.h> and <float.h>
- C Standard Library: 7 Variable Argument Lists: <stdarg.h>
- C Standard Library: 1 Input and Output: <stdio.h>
- c++ standard library <numeric> accumulate demo
- c++ standard library 学习笔记-auto_ptr<T> 注意事项
- C Standard Library:4 Mathematical Functions: <math.h>
- C Standard Library: 8 Non-local Jumps: <setjmp.h>
- C Standard Library: 9 Signals: <signal.h>
- C Standard Library: 10 Date and Time Functions: <time.h>
- C Standard Library:5 Utility Functions: <stdlib.h>
- 类 TreeMap<k,v> 遍历 TreeMap<String,String> 和TreeMap<Person,Person>
- Android实现List<String>存储到SharedPreferences工具类
- [Java 10 泛型] 泛型通配符 Info<?> i = new Info<String>(); 在程序中定义没有方法的接口,称之为标识接口
- 用string.Join与List<T>或者与string数组转换为字符串
- STL algorithm accumulate vector<string> demo
- List<Map<String,Object>> 不写limit在 Controller里面分页