国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

請高手講講C語言函數(shù)strtok()和memcpy()

2019-11-17 05:27:08
字體:
供稿:網(wǎng)友

  請高手講講在sco unix 5.xx版本下, c語言strtok()和memcpy()函數(shù)的使用。
(本問題的用意:分割字符串。)
最好能有c語言編程的源程序。

函數(shù)名: 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) ", 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;
}
函數(shù)名: memcpy
功 能: 從源source中拷貝n個字節(jié)到目標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;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 仪陇县| 马边| 长沙市| 苗栗市| 大关县| 微山县| 如皋市| 称多县| 木里| 福海县| 滁州市| 璧山县| 南郑县| 确山县| 福清市| 当涂县| 松阳县| 乌审旗| 安塞县| 定南县| 新邵县| 景德镇市| 司法| 潮安县| 常熟市| 呼图壁县| 织金县| 平定县| 金坛市| 襄汾县| 宣化县| 城市| 乌兰县| 芜湖县| 宜州市| 武夷山市| 临潭县| 华安县| 新昌县| 宜阳县| 洱源县|