WEB开发网      婵犻潧鍊婚弲顐︽偟椤栨稓闄勯柦妯侯槸閻庤霉濠婂骸浜剧紒杈ㄥ笚閹峰懘鎮╅崹顐ゆ殸婵炴垶鎸撮崑鎾趁归悩鐑橆棄闁搞劌瀛╃粋宥夘敃閿濆柊锕傛煙鐎涙ê鐏f繝濠冨灴閹啴宕熼鍡╀紘婵炲濮惧Λ鍕叏閳哄懎绀夋繛鎴濈-楠炪垽鎮归崶褍妲婚柛銊ュ缁傚秹鏁撻敓锟� ---闂佹寧娲╅幏锟�
开发学院软件开发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:高手 讲讲

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