原型:extern void *memcpy(void *dest, void *src, unsigned int count);
用法:#include <string.h>
功能:由src所指內(nèi)存區(qū)域復(fù)制count個(gè)字節(jié)到dest所指內(nèi)存區(qū)域。
說(shuō)明:src和dest所指內(nèi)存區(qū)域不能重疊,函數(shù)返回指向dest的指針。
舉例:
// memcpy.c
#include <syslib.h>
#include <string.h>
main()
{
char *s="Golden Global View";
char d[20];
clrscr();
memcpy(d,s,strlen(s));
d[strlen(s)]=0;
printf("%s",d);
getchar();
return 0;
}
原型:extern char *strchr(char *s,char c);
用法:#include <string.h>
功能:查找字符串s中首次出現(xiàn)字符c的位置
說(shuō)明:返回首次出現(xiàn)c的位置的指針,如果s中不存在c則返回NULL。
舉例:
// strchr.c
#include <syslib.h>
#include <string.h>
main()
{
char *s="Golden Global View";
char *p;
clrscr();
strchr(s,'V');
if(p)
printf("%s",p);
else
printf("Not Found!");
getchar();
return 0;
}
1 復(fù)制
?
char* strcpy (char *s1, const char *s2);
將字符串s2復(fù)制到s1指定的地址
?
char* strncpy (char *s1, const char *s2, size_t len);
void* ?memcpy (void *s1, const void *s2, size_t len);
將s2的前len個(gè)字符(字節(jié))復(fù)制到s1中指定的地址, 不加'\0'
?
void* memmove (void *s1, const void *s2, size_t len);
當(dāng)源單元和目的單元緩沖區(qū)交迭時(shí)使用
?
size_t strxfrm (char *s1, const char *s1, size_t len);
根據(jù)程序當(dāng)前的區(qū)域選項(xiàng), 將s2的前len個(gè)字符(字節(jié))復(fù)制到s1中指定的地址, 不加'\0'
?
2 連接
?
char* strcat (char *s1, const char *s2);
將字符串s2連接到s1尾部
?
char* strncat (char *s1, const char *s2, size_t len);
將字符串s2的前len個(gè)字符連接到s1尾部, 不加'\0'
?
3 比較
?
int strcmp (const char *s1, const char *s2);
比較字符串s1和s2
?
int strncmp (const char *s1, const char *s2, size_t len);
int ?memcmp (const void *s1, const void *s2, size_t len);
對(duì)s1和s2的前len個(gè)字符(字節(jié))作比較
?
int strcoll (const char *s1, const char *s2);
根據(jù)程序當(dāng)前的區(qū)域選項(xiàng)中的LC_COLLATE, 比較字符串s1和s2
?
4 查找
?
char* strchr (const char *s, int ch);
void* memchr (const void *s, int ch, size_t len);
在s中查找給定字符(字節(jié)值)ch第一次出現(xiàn)的位置
?
char* strrchr (const char *s, int ch);
在串s中查找給定字符ch最后一次出現(xiàn)的位置, r表示從串尾開(kāi)始
?
char* strstr (const char *s1, const char *s2);
在串s1中查找指定字符串s2第一次出現(xiàn)的位置
?
size_t strspn (const char *s1, const char *s2);
返回s1中第一個(gè)在s2中不存在的字符的索引(find_first_not_of)
?
size_t strcspn (const char *s1, const char *s2);
返回s1中第一個(gè)也在s2中存在的字符的索引(find_first_of)
?
char* strpbrk (const char *s1, const char *s2);
與strcspn類(lèi)似, 區(qū)別是返回指針而不是索引
?
char* strtok (char *s1, const char *s2);
從串s1中分離出由串s2中指定的分界符分隔開(kāi)的記號(hào)(token)
第一次調(diào)用時(shí)s1為需分割的字串, 此后每次調(diào)用都將s1置為NULL,
每次調(diào)用strtok返回一個(gè)記號(hào), 直到返回NULL為止
?
5 其他
?
size_t strlen (const char *s);
求字符串s的長(zhǎng)度
?
void* memset (void *s, int val, size_t len);
將從s開(kāi)始的len個(gè)字節(jié)置為val
?
char* strerror (int errno);
返回指向錯(cuò)誤信息字符串的指針
?
source: 《C & C++ Code Capsules》
posted on 2006-07-28 10:35
Bourne 閱讀(271)
評(píng)論(0) 編輯 收藏 引用