2016-04-29 84 views
4

下面我有一段代碼,我認爲它非常簡單,但由於某種原因無法正常工作,因爲我得到了錯誤savedMap.c:20:warning:隱式聲明瞭函數'fPrintf' 。該代碼是:寫入C文件

#include "Structures.h" 
#include "main.h" 
#include <stdio.h> 
#include <stdlib.h> 

void populateFile() { 
    printf("The method is being called"); 
    FILE *f = fopen("tempMap.txt", "w"); 
    if(f == NULL) { 
     printf("The tempMap file could not be found, please ensure the file is present."); 
    } 

    const char *text = mapFirstLine; 
    fPrintf(f, "Some text", text); 
} 
+4

'fPrintf'不存在。 'fprintf'確實。 –

+6

警告:_implicit聲明函數..._應始終視爲錯誤_ –

+1

如果您解決了問題,請將其標記爲已回答。 [如何將答案標記爲解決方案,爲什麼?](http://meta.stackexchange.com/a/5235/285305) –

回答

3

可以更換線路,而不是fprintf中(F, 「一些文本」,文本)以下;

fprintf(f, "Some text", text); 

由於fprintf中()在C不預定義的函數。

3

stdio.h中沒有fPrinf()功能。您可能需要使用標準庫函數fprintf()代替,就像這樣:

fprintf(f, "Some text", text); 

爲什麼一個「隱decalration」會發出警告的原因是,未聲明函數的返回值是int默認在C