Search code examples
cfilefile-writing

Writing to a file in C


Below i have a piece of code that i believe is very simple but for some reason will not work, as i get the error savedMap.c:20: warning: implicit declaration of function ‘fPrintf’. The code is:

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

Solution

  • You can replace below the line instead of fPrintf(f, "Some text", text);

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

    Because fPrintf () not predefined function in c.