小编bet*_*man的帖子

C++指向函数参数指针的指针

以下C++代码无法正常工作.

#include <string>
#include <iostream>

int Pointer_Function(char* _output);
int Pointer_to_Pointer_Function(char** text );

int main() {

    char* input = "This";
    printf("1. %s \n", input);
    Pointer_Function(input);
    printf("5. %s \n", input);

       int test;
       std::cin >> test;
}

int Pointer_Function(char* _output) {
       _output = "Datenmanipulation 1";
       printf("2. %s \n", _output);

       Pointer_to_Pointer_Function(&_output);

       printf("4. %s \n", _output);
    return 0;
}

int Pointer_to_Pointer_Function(char** text ) {

       printf("3. %s \n", *text);
       char* input = "HalliHallo";

       text = &input;
       printf("3.1. %s \n", *text);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望结果是printf 5. HalliHallo …

c++ parameters pointers

1
推荐指数
1
解决办法
227
查看次数

如何用百分之二取代百分号(%)?

我想尝试用两个%%符号替换char数组中的百分号.因为%符号会导致问题,如果我写为输出字符数组.因此,百分号必须用两个%%符号替换而不使用字符串.

// This array causes dump because of '%'
char input[] = "This is a Text with % Charakter";
//Therefore Percent Sign(%) must be replaced with two %%. 
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
1362
查看次数

C strcpy()不会剪切char字符

在Red Hat Linux上编写并运行下面的C++代码后,我感到很惊讶.

#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

int main()
{
 char natureofGoods[17];
 char *name="sadasdasdasdas171212";

 strcpy(natureofGoods,name);

 cout<<natureofGoods<<endl;
}
Run Code Online (Sandbox Code Playgroud)

我会在这里输出"sadasdasdasdas17"因为natureofGoods有17个字符大小.但我把整个字符串作为输出.我的意思是"sadasdasdasdas171212asdadsfsf"如果我在Visual Studio上运行此代码,那么在我等待时,我的程序会因调试消息而崩溃.为什么不strcpy切出17.名字的字符然后复制到natureofGoods

如何natureofGoods存储比其大小更多的特征?

c++ strcpy

0
推荐指数
1
解决办法
325
查看次数

标签 统计

c++ ×3

parameters ×1

pointers ×1

strcpy ×1