| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 503 人关注过本帖
标题:谁能帮我看下这程序出什么问题了,先谢谢了!
只看楼主 加入收藏
ToMoRRoWa
Rank: 1
来 自:保密
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-4-17
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:3 
谁能帮我看下这程序出什么问题了,先谢谢了!
图片附件: 游客没有浏览图片的权限,请 登录注册

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cerrno>

using std::cin;
using std::cout;
using std::endl;
using std::setw;

int _tmain(int argc, _TCHAR* argv[])
{
    const int MAX = 50;
    char Str1[MAX];
    char Str2[MAX];
    char* instead[MAX];
   
    cout << "请输入目标字符串:";
    cin.getline( Str1,MAX,'\n');
    cout << "请输入源字符串:";
    cin.getline( Str2,MAX,'\n');
   
    int count = 0;
    while( Str2 != 0 )
    {
        count ++;
        instead[count] = &Str2[count];
    }
    errno_t error = strcat_s(Str1,MAX,*instead);

    if( error == 0 )
    {
        cout << "恭喜,字符串拼接成功!"
             << endl
                << "拼接结果:" << strcat(Str1,*instead);
    }
    else
        if( error == EINVAL )
        cout << "字符串拼接失败,原因是目标或源为NULL";
    else
        if( error == ERANGE)
        cout << "字符串拼接失败,原因是目标长度太短";
    cout << endl
         << "Press any key . . .";
    _getch();
    return 0;
}
搜索更多相关主题的帖子: instead include 字符串 目标 
2010-05-02 16:47
xgpfree
该用户已被删除
收藏
得分:14 
提示: 作者被禁止或删除 内容自动屏蔽
2010-05-02 17:16
ToMoRRoWa
Rank: 1
来 自:保密
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-4-17
收藏
得分:0 
// 拼接字符串.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cerrno>
#include <cstring>

using std::cin;
using std::cout;
using std::endl;
using std::setw;

int _tmain(int argc, _TCHAR* argv[])
{
    const int MAX = 50;
    char Str1[MAX];
    char Str2[MAX];
    char* instead[MAX];
    int point = NULL;
   
    cout << "请输入目标字符串:";
    cin.getline( Str1,MAX,'\n');
    cout << "请输入源字符串:";
    cin.getline( Str2,MAX,'\n');
   
    int count = 0;
    while( point != '\0');
    {
        count ++;
        instead[count] = &Str2[count];
        point = Str2[count];
    }
    errno_t error = strcat_s(Str1,MAX,*instead);

    if( error == 0 )
    {
        cout << "恭喜,字符串拼接成功!"
             << endl
                << "拼接结果:" << strcat(Str1,*instead);
    }
    else
        if( error == EINVAL )
        cout << "字符串拼接失败,原因是目标或源为NULL";
    else
        if( error == ERANGE)
        cout << "字符串拼接失败,原因是目标长度太短";
    cout << endl
         << "Press any key . . .";
    _getch();
    return 0;
}
2010-05-02 17:30
玩出来的代码
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:河南新乡
等 级:贵宾
威 望:11
帖 子:742
专家分:2989
注 册:2009-10-12
收藏
得分:0 
程序代码:
    int count = 0;
    point=Str2[count];         
    while( point != '\0')
    {
        instead[count] = &Str2[count];     //改成这样吧,你那个instead[0]并没有指向,count++放在后面
        count ++;
        point = Str2[count];
    }

离恨恰如春草,更行更远还生。
2010-05-02 23:57
快速回复:谁能帮我看下这程序出什么问题了,先谢谢了!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012765 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved