以下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 …
我想尝试用两个%%
符号替换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) 在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
存储比其大小更多的特征?