用C写入文件

Writing to a file in C

下面有一段代码,我认为它非常简单,但由于某些原因无法正常工作,因为我收到错误 savedMap.c:20: 警告:函数‘fPrintf’的隐式声明。代码是:

#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);
}

您可以在该行下面替换而不是 fPrintf(f, "Some text", text);

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

因为fPrintf()不是c中预定义的函数

stdio.h中没有fPrinf()函数。您可能需要使用标准库函数 fprintf(),如下所示:

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

之所以发出"implicit decalration"警告是因为未声明函数的return值在C中默认为int