LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 690|回复: 6

[C/C++]基础问题。

[复制链接]
自由狼-台风 该用户已被删除
发表于 2005-11-17 09:42:39 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2005-11-17 11:08:56 | 显示全部楼层
在学习中
  
    可能是指针的问题,原因不太清楚,把
          size=strlen(p_strSource_1)+strlen(p_strSource_2)-1;
        p_strTarget=(char *)malloc(size);
     去掉,在main函数中增加
           int size=strlen(a)+strlen(b)-1;
           c=(char *)malloc(size);
   即可
回复 支持 反对

使用道具 举报

发表于 2005-11-17 11:25:06 | 显示全部楼层
size=strlen(p_strSource_1)+strlen(p_strSource_2)-1; 改成
size=strlen(p_strSource_1)+strlen(p_strSource_2)+1;
回复 支持 反对

使用道具 举报

发表于 2005-11-17 11:37:43 | 显示全部楼层
#include <stdio.h>
#include <string.h>

int superStrcat(char *p_strSource_1, char *p_strSource_2, char **p_strTarget)
{
        int size;

        size=strlen(p_strSource_1)+strlen(p_strSource_2) + 1;
        printf("size = %d\n", size);

        *p_strTarget=(char *)malloc(size);
        memset(*p_strTarget, 0, size);

        strcpy(*p_strTarget, p_strSource_1);
        printf("%s\n", *p_strTarget);

        strcat(*p_strTarget, p_strSource_2);
        printf("%s\n", *p_strTarget);

        return 0;
}

int main()
{
        char *a="123";
        char *b="4567890";
        char *c;

        superStrcat(a, b, &c);
        printf("a=%s\nb=%s\nc=%s\n", a, b, c);

        return 0;
}
回复 支持 反对

使用道具 举报

自由狼-台风 该用户已被删除
 楼主| 发表于 2005-11-17 13:01:17 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

发表于 2005-11-19 16:00:36 | 显示全部楼层
你问的什么意思?
用std::string:perator + 可以么?
#include <string>
using std::string

int main()
{
  string str1;
  string str2;
  ...
  str1= XXX  str2=XXXX
  ...
  string str3=str1+str2;
}
回复 支持 反对

使用道具 举报

发表于 2005-11-19 16:01:27 | 显示全部楼层
变表情了。。。
std :: string :: operator +
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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