Chinaunix首页 | 论坛 | 博客
  • 博客访问: 436698
  • 博文数量: 89
  • 博客积分: 2713
  • 博客等级: 少校
  • 技术积分: 938
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-18 21:19
个人简介

为了成为自由自在的人而奋斗!

文章分类

全部博文(89)

文章存档

2016年(5)

2015年(9)

2014年(2)

2013年(10)

2012年(1)

2011年(30)

2010年(32)

分类: C/C++

2011-09-02 11:03:35

/**
 * 有字符串input:"abc ccc   faf   awre"以空格隔开,
 * 要求编写函数实现output:"abc,ccc,faf,awre,"
 *
 * len为output长度,足够长
 * void my_test(const char *input, char *output, int len);
 */
#include
#include
#include
 
void my_test(const char *input, char *output, int len)
{
 char *p;
 
 if (input == NULL || output == NULL) {
  return;
 }
 
 memset(output, 0, len);
 p = strtok(input, " ");
 while (p) {
  strcat(output, p);
  strcat(output, ",");
  p = strtok(NULL, " ");
 }
 
 printf("%s\n", output);
}
阅读(753) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~