zoukankan      html  css  js  c++  java
  • 面试题

    #include<iostream>
    #include<STRING>
    using namespace std;
    int main()
    {
       char *src = "hello world";
       char * dest = NULL;
       int len = strlen(src);
       //cout<<len<<endl;
       dest = (char *)malloc(len);
       char *d =dest;
       char * s =src[len];
       while (len--!=0)
       {
        d++ = s--;
        cout<<dest;
       }
       return 0; 
    }

    改正后的

    #include<iostream>
    using namespace std;
    int main()
    {
       char *src = "hello world";
       char * dest = NULL;
       int len = strlen(src);
       dest = (char *)malloc(len);
       char *d =dest;
       char * s = &(src[len]);//*S此时为 '\0'

       len = len + 1;
       while ( len--!= 0)
        *d++ = *s--;     //这里要循环Len + 1次
       
       len = strlen(src);
       for (int i =0; i<=len - 1; i++)  //将d还原
        d--;
       cout<<"d="<<d<<endl;

       return 0; 
    }

    输出结果 为  hello world 的反转

     参考 strcopy 的写法,也可以这样写

      while ((*d++ = *s--) != *src)
       NULL; 

  • 相关阅读:
    Spring国际化模块
    广告牌 循环 轮播 图片
    ImageLoader 网络加载图片
    ProgressBar 进度条 旋转
    UI处理 线程
    权限 动态 访问
    系统 状态栏 导航栏
    对话框 dialog 整理
    修改 字体
    获取 Activity中所有的View ViewGroup
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1378645.html
Copyright © 2011-2022 走看看