gpt4 book ai didi

c - 使用 C 标准库从 url 读取/写入文件的最佳方法

转载 作者:太空宇宙 更新时间:2023-11-04 08:23:05 25 4
gpt4 key购买 nike

我正在构建一个简单的 C 程序,它使用 scanf() 获取用户输入参数 (URL),如下面的代码所示。我现在正在寻找将远程文件读/写到本地文件的最佳“标准”方式...然后我将对新的本地源文件执行 grep(搜索)操作。

//代码

#include <stdio.h>

int main(void){
char url[255];

//USER INPUT URL
printf("ENTER URL: ");
scanf("%s", &url);

//GET FILE AT URL(REMOTE) AND COPY TO (LOCAL)




//RETURN
return 0;
}

最佳答案

老实说,您可以使用 libcurl,或者直接使用 wgetcurl

char command[1024];
snprintf(command, 1024, "wget -c '%s'", url);
system(command); // add error handling

这将大大减少工作量。

关于c - 使用 C 标准库从 url 读取/写入文件的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com