c - 将 CURLcode res 转换为 char*
问题描述
我想接收要使用的网页内容。所以我需要将内容存储在变量char*
/string
由于您可以显示内容,printf
因此我试图使用它sprintf
来查看我是否可以存储内容,但它根本不起作用
int main () {
CURL *curl = curl_easy_init();
char rstr[80];
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://api.binance.com/api/v3/png");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
printf("%u\n",res);
sprintf(rstr,"%u\n",res);
}
printf("%s\n",rstr);
return 0;
}
输出是:
<html><body><h2>404 Not found</h2></body></html>0
0
虽然期待:
<html><body><h2>404 Not found</h2></body></html>0
<html><body><h2>404 Not found</h2></body></html>0
这意味着printf("%u\n",res);
显示内容和额外的 0。
但sprintf(rstr,"%u\n",res);
仅包含 0 而没有站点内容。
如何将内容转换/存储为char[]
,char*
或string
?
解决方案
推荐阅读
- python - 在 Windows 上运行时,如何强制 pandas 1.0.3 编写编码为 UTF-8 的 csv?
- postgresql - postgresql 在 SELECT 中的一列中应用不同的
- flutter - 做什么
颤抖的意思? - listview - 打印时列表值正确,但使用时列表为空 Flutter
- sql - 重写 Oracle SQL 自联接查询
- wordpress - WordPress 子域
- ios - 如何在注销时快速清空数组
- css - 相对于视口的右边缘平移元素
- python - 在 Jupyter 中导出多行 SQL
- wpf - 从 WPF 数据网格解决方案中检索数据一种有效,一种无效