this is a gaga return into gaga a is this
来源:互联网 发布:少女前线五星枪数据 编辑:程序博客网 时间:2024/06/17 19:46
例如:(唉~~,实践知识到用时,方恨少啊。。。回家老老实实写了个半小时才写完的。。。可能边界情况没有考虑充分。。。)
int _tmain(int argc, _TCHAR* argv[])
{
char *str = (char*)malloc(15);
char *str_words[MAXLEN], *p_str = str;
strcpy(str,"this is a dog");
int word_num = readwords(str, str_words);
int tmp_cnt =0, char_num = 0;
for (; tmp_cnt < word_num; tmp_cnt++ )
{
char_num = strlen(str_words[word_num-tmp_cnt-1]);
memcpy(str, str_words[word_num-tmp_cnt-1],char_num);
str +=char_num;
*str++ = ' ';
}
*str = '/0';
cout<<p_str<<endl;
return 0;
}
/* str is the words array, str_words is the output arrays */
int readwords(char * str, char *str_words[])
{
int words_cnt = 0;
int word_len = 0;
char *p = NULL;
char word[MAXLEN];
/*later for the conner case */
if ( NULL == str )
{
return 0;
}
word_len = getword(word,str);
p = (char*)malloc(word_len);
strcpy(p, word);
str_words[words_cnt++] = p;
str += (word_len - 1);
while( *str != '/0')
{
if((*str == ' ') || (*str == '/t'))
{
word_len = getword(word,++str);
p = (char*)malloc(word_len);
strcpy(p, word);
str_words[words_cnt++] = p;
str += (word_len - 1);
}
else
{
str++;
}
}
return words_cnt;
}
int getword(char *word, char *str)
{
int word_len = 0;
if(NULL == str)
{
return 0;
}
while((*str != ' ')&&(*str != '/0'))
{
word_len++;
*word++ = *str++;
}
if((*str == ' ') || ( *str == '/0'))
{
*word = '/0';
word_len++;
}
return word_len;
}
- this is a gaga return into gaga a is this
- gaga
- gaga
- gaga
- gaga
- This is a test
- this is a demo:)
- This is a test
- This is a test
- This is a test
- this is a test
- This is a test
- This is a test~!
- this is a test
- This is a test
- This is a Test
- This is a triumph!
- This is a test
- Java 7新特性(九)——动态语言支持
- Windows CE操作系统的触摸屏驱动程序模型
- ubuntu----PPA
- SQL Server 2008 数据库镜像部署实例之二
- 探秘Java 7 新增垃圾回收器G1特性
- this is a gaga return into gaga a is this
- 网站百度不收录情况解析
- 基于Windows CE的7×3手机键盘驱动实现
- 探秘Java 7 新增垃圾回收器G1特性
- SQL Server 2008 数据库镜像部署实例之二
- VIM开发C/C++插件cvim的安装及使用
- JDK 7 M5包含了并发性和性能更新,但功能并不完整
- Excel小游戏_魂斗罗再现[分享]
- SQL Server 2008 数据库镜像部署实例之三