Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何修理_C_File_Curl - Fatal编程技术网

C 如何修理

C 如何修理,c,file,curl,C,File,Curl,我的程序应该从文件links.txt中的URL下载所有文件。该文件的最后一行是:end。 我不知道我做错了什么,但编译后我没有任何警告,但当我运行我的程序时,我得到了核心转储错误。有人有什么建议吗?我能正确读取的文件 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <curl/curl.h> size_t write_data(void *ptr, size_

我的程序应该从文件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;
}
#包括
#包括
#包括
#包括
大小写入数据(void*ptr、大小、大小nmemb、文件*流){
写入的大小=写入(ptr、大小、nmemb、流);
书面回报;
}
int main(){
卷曲*卷曲;
curl\u global\u init(curl\u global\u ALL);
curl=curl_easy_init();
文件*fp;
文件*fl;
fl=fopen(“links.txt”,“r”);
字符url[1000];
fgets(url,1000,fl);
while(strcmp(url,“end”)!=0){
char*name=strstrstr(url,“http”);
name=name+7;
fp=fopen(名称,“wb”);
curl_easy_setopt(curl,CURLOPT_URL,URL);
curl\u easy\u setopt(curl,CURLOPT\u WRITEFUNCTION,write\u data);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp);
旋度,易于执行(旋度);
fclose(fp);
fgets(url,1000,fl);
}
旋度\轻松\清洁(旋度);
fclose(fl);
返回0;
}

while(strcmp(url,“end”)!=0){
strcmp将始终返回一个非零值,因为fgets()返回的字符串中仍然附加了“\n”。因此最终的
fp=fopen(name,“wb”);
将失败,因为它绑定到打开名为“end\n”的文件。Asko:您可以从fopen()检查返回值如果文件不存在,它可能会失败。你能尝试使用
wget
吗不幸的是,我不能使用wget,因为它太小了easy@wildplasser我忘了写文件links.txt的最后一行是:endLean如何使用调试器。