随笔 - 7  文章 - 15  trackbacks - 0
<2006年7月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(2)

随笔档案(7)

相册

搜索

  •  

积分与排名

  • 积分 - 15536
  • 排名 - 944

最新评论

阅读排行榜

评论排行榜

原型:extern void *memcpy(void *dest, void *src, unsigned int count);

用法:#include <string.h>

功能:由src所指内存区域复制count个字节到dest所指内存区域。

说明:src和dest所指内存区域不能重叠,函数返回指向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中首次出现字符c的位置

说明:返回首次出现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 复制

 

char* strcpy (char *s1, const char *s2);
将字符串s2复制到s1指定的地址

 

char* strncpy (char *s1, const char *s2, size_t len);
void*  memcpy (void *s1, const void *s2, size_t len);
s2的前len个字符(字节)复制到s1中指定的地址, 不加'\0'

 

void* memmove (void *s1, const void *s2, size_t len);
当源单元和目的单元缓冲区交迭时使用

 

size_t strxfrm (char *s1, const char *s1, size_t len);
根据程序当前的区域选项, s2的前len个字符(字节)复制到s1中指定的地址, 不加'\0'

 


2
连接

 

char* strcat (char *s1, const char *s2);
将字符串s2连接到s1尾部

 

char* strncat (char *s1, const char *s2, size_t len);
将字符串s2的前len个字符连接到s1尾部, 不加'\0'

 


3
比较

 

int strcmp (const char *s1, const char *s2);
比较字符串s1s2

 

int strncmp (const char *s1, const char *s2, size_t len);
int  memcmp (const void *s1, const void *s2, size_t len);
s1s2的前len个字符(字节)作比较

 

int strcoll (const char *s1, const char *s2);
根据程序当前的区域选项中的LC_COLLATE, 比较字符串s1s2

 


4
查找

 

char* strchr (const char *s, int ch);
void* memchr (const void *s, int ch, size_t len);

s中查找给定字符(字节值)ch第一次出现的位置

 

char* strrchr (const char *s, int ch);
在串s中查找给定字符ch最后一次出现的位置, r表示从串尾开始

 

char* strstr (const char *s1, const char *s2);
在串s1中查找指定字符串s2第一次出现的位置

 

size_t strspn (const char *s1, const char *s2);
返回s1中第一个在s2中不存在的字符的索引(find_first_not_of)

 

size_t strcspn (const char *s1, const char *s2);
返回s1中第一个也在s2中存在的字符的索引(find_first_of)

 

char* strpbrk (const char *s1, const char *s2);
strcspn类似, 区别是返回指针而不是索引

 

char* strtok (char *s1, const char *s2);
从串s1中分离出由串s2中指定的分界符分隔开的记号
(token)
第一次调用时s1为需分割的字串, 此后每次调用都将s1置为
NULL,
每次调用strtok返回一个记号, 直到返回NULL为止

 


5
其他

 

size_t strlen (const char *s);
求字符串s的长度

 

void* memset (void *s, int val, size_t len);
将从s开始的len个字节置为val

 

char* strerror (int errno);
返回指向错误信息字符串的指针

 

source: C & C++ Code Capsules
posted on 2006-07-28 10:35 Bourne 阅读(256) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理