Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months ago.
fopen local file system not working
Having issues with fopen when trying to open a file in binary mode. When using binary mode the *fp pointer returns NULL every time. The file to open does exist and is located on the local file system. What am I doing wrong?
This fails
#include "mbed.h" #include "LPC17xx.h" /* LPC17xx definitions */ #include "PPD_CAN.h" #include "rtos.h" #include <iostream> // library that contain basic input/output functions #include <fstream> // library that contains file input/output functions using namespace std; //Open binary file to write FILE *fp = fopen(PATH_TO_BINARY, "rb"); // This fails and returns NULL every pass if (fp == NULL) { pc.printf("Failed to open binary.\n"); return -1; } else { pc.printf("File opened successfully\n"); //Get some work done here fclose(fp); }
This works
#include "mbed.h" #include "LPC17xx.h" /* LPC17xx definitions */ #include "PPD_CAN.h" #include "rtos.h" #include <iostream> // library that contain basic input/output functions #include <fstream> // library that contains file input/output functions using namespace std; //Open binary file to write FILE *fp = fopen(PATH_TO_BINARY, "r"); // This works every pass if (fp == NULL) { pc.printf("Failed to open binary.\n"); return -1; } else { pc.printf("File opened successfully\n"); //Get some work done here fclose(fp); }
1 Answer
5 years, 8 months ago.
Hi Rob - did you ever manage to get to the bottom of this problem? I may be encountering a similar issue...
Just tried the following which also does not work when Binary mode is used. Is this a bug? Is the local file system not accessible when reading a file as a binary.
Does not work