我的程序应该从文件 links.txt 中的URL下载所有文件。该文件的最后一行是:end。 我不知道我做错了什么,但是我在编译后没有任何警告,但是当我运行我的程序时,我得到核心转储故障。有人有什么建议吗?我可以正确阅读的文件。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main() {
CURL *curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
FILE *fp;
FILE *fl;
fl=fopen("links.txt", "r");
char url[1000];
fgets(url, 1000, fl);
while(strcmp(url,"end")!=0) {
char *name=strstr(url, "http");
name = name+7;
fp = fopen(name,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_perform(curl);
fclose(fp);
fgets(url, 1000, fl);
}
curl_easy_cleanup(curl);
fclose(fl);
return 0;
}