WEB开发网
开发学院软件开发C++ 请高手讲讲C语言函数strtok()和memcpy() 阅读

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

 2008-03-08 12:55:05 来源:WEB开发网   
核心提示:请高手讲讲在sco unix 5.xx版本下, c语言strtok()和memcpy()函数的使用,请高手讲讲C语言函数strtok()和memcpy(),(本问题的用意:分割字符串,)最好能有c语言编程的源程序

  请高手讲讲在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;
}

Tags:高手 讲讲

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接