2013-12-07 38 views
-1

如何不顯示所有這些信息? 我所做的只是使用一些編輯過的FTP例子,我不希望顯示這些信息。Libcurl如何不顯示所有這些信息

編輯:在加入鏈接全代碼的main.c

圖像:http://www.mediafire.com/convkey/71e9/oyhctzcdjxakzxzfg.jpg

#include <stdio.h> 
#include <stdlib.h> 
#include <curl/curl.h> 

struct FtpFile { 
const char *filename; 
FILE *stream; 
}; 
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) 
{ 
    struct FtpFile *out=(struct FtpFile *)stream; 
    if(out && !out->stream) { 
    /* open file for writing */ 
    out->stream=fopen(out->filename, "wb"); 
    if(!out->stream) 
    return -1; /* failure, can't open file to write */ 
} 
return fwrite(buffer, size, nmemb, out->stream); 
} 

int main() 
{ 
CURL *curl; 
CURLcode res; 
struct FtpFile version={"version.txt", /* name to store the file as if succesful */NULL}; 

curl_global_init(CURL_GLOBAL_DEFAULT); 
curl = curl_easy_init(); 

FILE *file_verzija; 
int trenutna_verzija; 
int nova_verzija; 
char pitanje_za_update; 

file_verzija=fopen("version.txt","r"); 

fscanf(file_verzija,"%i",&trenutna_verzija); 

fclose(file_verzija); 


printf("Current version %i",trenutna_verzija); 

printf("\nChecking for updates...\n"); 


if(curl) 
{ 
    /*You better replace the URL with one that works!*/curl_easy_setopt(curl, CURLOPT_URL,"http://elektro-srb.com/site/muffin_finder_files/version.txt"); 
    /* Define our callback to get called when there's data to be written */ 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); 
    /* Set a pointer to our struct to pass to the callback */ 
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &version); 
    /* Switch on full protocol/debug output */ 
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); 
    res = curl_easy_perform(curl); 
    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    if(CURLE_OK != res) 
    { 
     /* we failed */ 
     printf("\nerror"); 
    } 
} 

if(version.stream) 
    fclose(version.stream); /* close the local file */ 

file_verzija=fopen("version.txt","r"); 

fscanf(file_verzija,"%i",&nova_verzija); 

fclose(file_verzija); 

if(trenutna_verzija != nova_verzija) 
{ 
    printf("\nUpdate found! New version is %i",nova_verzija); 
} 
else 
{ 
    printf("You are running latest version of Muffin Finder!"); 
} 

if(trenutna_verzija != nova_verzija) 
{ 
    printf("\nUpdate? y/n"); 
    scanf("\n%c",&pitanje_za_update); 
    if((pitanje_za_update == 'y') || (pitanje_za_update == 'Y')) 
    { 
     //UPDATE 
    } 
    else if((pitanje_za_update == 'n') || (pitanje_za_update == 'N')) 
    { 
     //pokretanje stare 
    } 
} 


curl_global_cleanup(); 



return 0; 
} 

回答

0

comment line following:

curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);

+0

謝謝!那正是我想要的! – user3078694

+0

不客氣,@ user3078694 :) –

1

您應該建立一個WRITEFUNCTION選項,以防止它使用stdout進行打印。

請看這裏:http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

搜索「WRITEFUNCTION」。你應該實現這個功能(並且我假設你想把它留空)。

編輯:作爲手動狀態,你應該做到以下幾點:

實現一個函數來替換默認標準輸出

size_t outputFunction(char *ptr, size_t size, size_t nmemb, void *userdata) {}

當初始化捲曲結構,使用此選項:

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, outputFunction);

+0

其實我不是編程的神,所以我需要更多的幫助:)你能告訴我究竟該做什麼嗎? 我添加了代碼 – user3078694

+0

好像你添加的代碼只是一個複製的代碼.. – Novak

+0

你是什麼意思複製一個?我使用了http://curl.haxx.se/中的ftpget.c示例,並添加了一些文本文件閱讀功能?我只是不明白你說我做什麼,所以我要求更詳細的幫助。 – user3078694

相關問題