2016-04-29 104 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