Search code examples
c++microprocessors

Too few arguments to function 'int fclose(FILE*)'


Hello I am a beginner of C language for microprocessors. I want to read a ''.bmp'' file in order to apply line detection on it. I have declared a function to read the image. This error occurs when compile button is pushed:

#include "esp_camera.h"
#include "Arduino.h"
#include "FS.h"                // SD Card ESP32
#include "SD_MMC.h"            // SD Card ESP32
#include "soc/soc.h"           // Disable brownour problems
#include "soc/rtc_cntl_reg.h"  // Disable brownour problems
#include "driver/rtc_io.h"
#include <EEPROM.h>            // read and write from flash memory
#include <SPI.h>

  void imageReader(const char *imgName,
    int *height,
    int *width,
    int *bitdepth,
    unsigned char *header,
    unsigned char *_colortable,
    unsigned char *buf
    ) // READ AN IMAGE
  {
     int i;
     fs::FS &fs = SD_MMC;  // 
     FILE *file;
     file = fopen(imgName,"rb"); // read imgName file ( it is a picture in .bmp format )
     if(!file){
        Serial.printf("Unable to read image");
     }
     for(i=0 ; i<54 ; i++){
        header[i]=getc(file);
     }
     *width = *(int * )& header[18]; // width information of the image
     *height = *(int * )& header[22]; // height information of image
     *bitdepth = *(int *)& header[28];
     if(*bitdepth<=8){
        fread(_colortable,sizeof(unsigned char),1024,file);
     }
     fread(buf,sizeof(unsigned char),( 1600 * 1200 ) ,file);
     fclose();
    }

It gives this error. too few arguments to function 'int fclose(FILE*)'


Solution

  • The fclose() function needs to know which file to close. You need to tell it that by supplying "file" as an argument. You want to use fclose(file).