请高手讲讲C语言函数strtok()和memcpy()

王朝c/c++·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

请高手讲讲在sco unix 5.xx版本下, c语言strtok()和memcpy()函数的使用。

(本问题的用意:分割字符串。)

最好能有c语言编程的源程序。

函数名: strtok

功 能: 查找由在第二个串中指定的分界符分隔开的单词

用 法: char *strtok(char *str1, char *str2);

#include <string.h>

#include <stdio.h>

int main(void)

{

char input[16] = "abc,d";

char *p;

/* strtok places a NULL terminator

in front of the token, if found */

p = strtok(input, ",");

if (p) printf("%s

", p);

/* A second call to strtok using a NULL

as the first parameter returns a pointer

to the character following the token */

p = strtok(NULL, ",");

if (p) printf("%s

", p);

return 0;

}

函数名: memcpy

功 能: 从源source中拷贝n个字节到目标destin中

用 法: void *memcpy(void *destin, void *source, unsigned n);

程序例:

#include <stdio.h>

#include <string.h>

int main(void)

{

char src[] = "******************************";

char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";

char *ptr;

printf("destination before memcpy: %s

", dest);

ptr = memcpy(dest, src, strlen(src));

if (ptr)

printf("destination after memcpy: %s

", dest);

else

printf("memcpy failed

");

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航