2011-12-23 7 views
0

次のように私のコードは次のとおりです。警告:パラメータリスト内で宣言「curl_fileinfo構造体」

#include <curl/curl.h> 
struct callback_data { 
     FILE *output; 
     char *path; //to specify the entire path 
     char *fname; //Full file name of current download 
     char *msg; //message for display 
};    

static long file_is_comming(struct curl_fileinfo *finfo, struct callback_data *data, int remains); 

static long file_is_downloaded(struct callback_data *data); 

static size_t write_it(char *buff, size_t size, size_t nmemb, 
         struct callback_data *data); 

static long file_is_comming(struct curl_fileinfo *finfo, struct callback_data *data, int remains) 
{ 
     printf("%3d %40s %10luB ", remains, finfo->filename, (unsigned long)finfo->size); 

     printf("dest path = %s \n", data->path); 
     if(finfo->filetype == CURLFILETYPE_FILE) { 

       data->fname = (char *)malloc((sizeof(char *)) * 
           (strlen(finfo->filename) + strlen(data->path)+1)); 

       sprintf(data->fname, "%s%s", data->path, finfo->filename); 
       data->output = fopen(data->fname, "w"); 
     printf("dest file name = %s \n", data->fname); 

       if(!data->output) { 
         return CURL_CHUNK_BGN_FUNC_FAIL; 
       } 
     } 

     return CURL_CHUNK_BGN_FUNC_OK; 
} 

警告は、次のとおりです。

warning: 'struct curl_fileinfo' declared inside parameter list 
warning: 'struct curl_fileinfo' declared inside parameter list 
utils-curl.h:15: warning: its scope is only this definition or declaration, which is probably not what you want 
utils-curl.c:3: warning: 'struct curl_fileinfo' declared inside parameter list 
utils-curl.c:4: error: conflicting types for 'file_is_comming' 
utils-curl.h:15: error: previous declaration of 'file_is_comming' was here 
+0

てみてください:

以外の警告から、私はあなたにも、以下のエラーになるはずだと思います。 –

+0

Googleは '#include 'を提案しているか、@Daveのように前方宣言しています。 –

+0

私はそれを含んでいます...(Plesaeはデフォルトでそれを取る) – john

答えて

1

あなたはどちらかstruct curl_fileinfoを宣言前方適切なヘッダーを含める、またはする必要があります関数定義の中のポインタを使用する前に。

0

次のような行為は、あなたがしたいことではないかもしれないと思います!私はあなたが

10     data->fname = (char *)malloc((sizeof(char)) * 
11         (strlen(finfo->filename) + strlen(data->path)+1)); 

sizeof(char)をしないsizeof(char *)

あなたが入力する必要がありますしたいと思います

10     data->fname = (char *)malloc((sizeof(char *)) * 
11         (strlen(finfo->filename) + strlen(data->path)+1)); 

sizeof()戻りsize_tなくintのでintsizeof()の出力をキャスト。

OTOH、mallocさのメモリを使用する前に、あなたはチェックmalloc()かどうかが成功するかしなければなりません!適切なヘッダを含む

utils-curl.c:4: error: conflicting types for 'file_is_comming' 
    utils-curl.h:15: error: previous declaration of 'file_is_comming' was here 
関連する問題