打印出字符串指针中获得的数据时出错
我正在尝试调用接口函数并打印出结果值。函数原型包含指向字符串的指针作为参数。当我打印结果值时,我收到一些奇怪的符号。我的以下方法正确吗?
int interfacecall(char *a, char *b ...);
char * a= "Testdata";
char b [4098];
result= interfacecall(a,b);
//different value is returned in b via function implementation in a third party dll.
printf(b);
I am trying to call an interface function and print out the resulting values. The function prototype contains pointers to character string as arguments. When I print out the resulting values I receive some strange symbols. Is my below approach correct?
int interfacecall(char *a, char *b ...);
char * a= "Testdata";
char b [4098];
result= interfacecall(a,b);
//different value is returned in b via function implementation in a third party dll.
printf(b);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 printf 不太安全。它应该是:
在 C++ 中,您还可以使用
std::cout
作为:确保
b
是一个以 null 结尾的 c 字符串,否则它将打印垃圾并且可能会使你的程序崩溃。空终止字符串意味着它必须以\0
结尾。像这样的东西:Your printf is not that safe. It should be :
In C++, you can also use
std::cout
as:Make sure that
b
is a null-terminated c-string, otherwise it wil print garbage and may crash your program. Null-terminated string means it must end with\0
. Something like this: