单词倒转

来源:互联网 发布:金钱永不眠软件 编辑:程序博客网 时间:2024/04/29 02:39
/*如何实现这个算法
This is a good day today -> sihT si a doog yad yadot */

<script type="text/javascript"><!--google_ad_client = "pub-3555979289815451";google_ad_slot = "0437120238";google_ad_width = 468;google_ad_height = 60;//--></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

#include "stdafx.h"
#include "string.h"
#include "malloc.h"

char *fun(char *a);

int main(int argc, char* argv[])
{
   char *string = "This is a good day today";
   char *ll=fun(string);
   printf("%s",ll);
   return 0;
}
 
char *fun(char *a)
{
   char *ptt = (char *)malloc(strlen(a));
   ptt = a;
   char *ftt = (char *)malloc(strlen(a));
   *ftt = '/0';
   char step[] = " ";
   char *token;
   token = strtok( strdup(a),step);
/*strtok()检索字符串s1,该字符串s1是由字符串s2中定义的定界符所分隔*/
/*strdup()将字符串s复制到最近建立的单元*/
   while(token != NULL)
   {
      strcat(ftt,strrev(token)); /*strrev()将字符串s复制到最近建立的单元*/
      strcat(ftt," ");
      token = strtok( NULL,step);
   }
   *(ftt + strlen(a)-1) = '/0';
   return  ftt;
}
原创粉丝点击