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.
7 years, 10 months ago.
Reading intergers from a file and stroing it in an array using LocalFileSystems.
I have a text file that I have created on the MBed from which I need to read the integers values and store it in an array. The content of the file is single spaced integers, eg
0 1 0 1 0 0 0 1 0 1 0 .....
I want to read this in using file systems and store it in an array. This is the code that I am using but it dies not give me any result.
include the mbed library with this snippet
#include "mbed.h" LocalFileSystem local("local"); //2D array to keep record of the solved maze int sol[9][9] = { {1,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, }; int main() { FILE *fp2 = fopen("/local/out.txt", "r"); for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { fscanf(fp2, "%d", &sol[i][j]); } } fclose(fp2); }
What am I doing wrong?
Where do you define sol?
posted by Erik - 08 May 2017I had only put the part of the code where I scan the integers from the text file. I have now updated it to include the entire code.
posted by Sangam Singh 08 May 2017