Unreachable Statement?

13 Mar 2013

Hello everyone, This is my start from previous post....SD card is still in post! I get the following error when I compile it and it's so far into the .cpp code I get lost what it refers to? statement is unreachable-resource ff.cpp-line 1689, Col 12 Original code is from the book Example 10.4.

#include "mbed.h"
#include "GPS.h"
#include "TextLCD.h"
#include "SDFileSystem.h"

Serial pc(USBTX, USBRX);
GPS gps(p13, p14);
TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
SDFileSystem sd(p5, p6, p7, p8, "sd"); //MOSI, MISO, SCLK, CS


int main()
{ FILE *File = fopen("/sd/GPSReadData.txt", "a"); //open file for GPS data and append data
if (File ==NULL) { //check for file pointer
lcd.locate(0,0);
lcd.printf("Could not open file"); //error if no pointer
}
else{
lcd.locate(0,0);
lcd.printf("SD cardfile open ok"); //pointer worked!
}
wait(2.0);

    //while(something yet to be defined) {
        if(gps.sample()) {
            lcd.locate(0,0);
            lcd.printf("Lg %f\n", gps.longitude);
            fprintf(File, "LG %f\n", gps.longitude); //append data
            lcd.locate(0,1);
            lcd.printf("Lt %f\n", gps.latitude);
            fprintf(File, "Lt %f\n", gps.latitude); //append data
        } else {
            lcd.printf("Oh Dear! No lock :(\n");
      //  }
    }fclose(File);
}

Once I have the data on SDCard I think the next obvious questions will be around the format of the saved data and how to read it......but let me struggle with that first!

Many thanks as always for any and all help. Degs

27 Sep 2013

i think you must close file before }else