吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3771|回复: 2
收起左侧

[其他转载] 一条习题懂希望有心人讲解讲解..

 关闭 [复制链接]
kimberaly 发表于 2010-4-18 16:06
本帖最后由 kimberaly 于 2010-4-18 16:10 编辑

原题是:
int main()
{
 char str1[]={"Tomato Studio"};
 char *str2;
 int size=________________;
 str2=_______;
 cout<<"STR1的内容是"<<str1<<endl;
 strcopy(str1,str2);
 cout<<"String Copied..."<<endl;
 cout<<"STR2的内容是"<<str2<<endl;
         __________;
 return 0;
}
void strcopy(char *string1,char *string2)
{
 for(char *temp=______;*temp!='\0';*temp=______)
 {
  _________;
  string2++;
 }
         _________;
}


我自己补充后:
#include <iostream.h>
void strcopy(char *string1,char*string2);
int main()
{
        char str1[]={"Tomato Studio"};
        char *str2;
        int size=sizeof(str1)/sizeof(char);
        str2=new char[size];
        cout<<size<<endl;
        cout<<"STR1的内容是"<<str1<<endl;
        strcopy(str1,str2);
        cout<<"String Copied"<<endl;
        cout<<"STR2的内容是"<<str2<<endl;
        delete []str2;
        return 0;
}
void strcopy(char *string1,char*string2)
{

        for(char *temp=string1;*temp!='\0';temp++)
        {
                string2[0]=temp[0];
                string2++;

        }
        _________;//这里不知怎样填,但上百度一查后,得知可以这样*string2 = '\0';或这样写*string2=*temp;我就是不能白这里为何要这样写...
}


我知道明次同学也在学C++一起进来研究研究吧[s:214]

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

kings0527 发表于 2010-4-18 20:49
\0     就是传说中的结束标志  呵呵
其实应该很早很早没有学习语言之前学习破解的时候   你会在OD或者C32中看到字符串结尾后都是以.....—点点点—来结束。最常见的就是输入表  API和dll模块的名字都是以....结束
这个应该在很多C语言的书籍中都有说的——比如hello world  正常存储后是 hello world\0
我想你可能知道是结束标志   只是不理解为什么这样吧
因为前面for循环后 string2++   当  *temp=string1;*temp!='\0';temp++  这句 string1加到最后一个字符也就是\0了,所以*temp也是\0,所以for循环内的复制不会执行了,但是此时——譬如是hello world——这个字符串还没有真正的在内存中结束,所以此时给他——*string2——也就是world后面的中的d这个字母的后面赋值为0表示结束。
貌似解释的够清晰了。日行一善
 楼主| kimberaly 发表于 2010-4-19 09:45
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 16:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表