GPS Logging Code Check and Advice

Good Afternoon buddies, im in the process of building a gps datalogger, without any complex code, but due to my bad programmin skills I modified some code which I found on the internet. Please advice if its correctly written.

Thanks folks

/********************************************************************
* SD card GPS logger
* Distributed under GPL v2.0
* Copyright (c) 2012 Stanley Huang All rights reserved.
********************************************************************/
#include <SD.h>

#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F"
#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C"
#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"

#define SD_CHIP_SELECT 10

File sdfile;

static char filename[13];
static bool fileOpened = false;

bool openSDFile()
{
    // open log file
    for (unsigned int index = 0; index < 65535; index++) {
        char filename[16];
        sprintf(filename, "GPS%05d.TXT", index);
        if (!SD.exists(filename)) {
            sdfile = SD.open(filename, FILE_WRITE);
            if (sdfile) {
                return true;
            };
            break;
        }
    }
    return false;
}

void setup()
{
    Serial.begin(115200);

    // Set the update rate
    // 1 Hz update rate
    //Serial.println(PMTK_SET_NMEA_UPDATE_1HZ);
    // 5 Hz update rate
    Serial.println(PMTK_SET_NMEA_UPDATE_5HZ);
    // 10 Hz update rate
    //Serial.println(PMTK_SET_NMEA_UPDATE_10HZ);

    // initialize the digital pin as an output.
    // Pin 13 has an LED connected on most Arduino boards:

    // enable SD card
    pinMode(SD_CHIP_SELECT, OUTPUT);
    if (SD.begin(SD_CHIP_SELECT)) {
        fileOpened = openSDFile();
    }
    delay(3000);
}

void loop()
{
    static int byteCount = 0;
    static unsigned long lastTime = 0;
    static unsigned int recDataKB = 0;

    if (!Serial.available()) return;

    char c = Serial.read();
    // dump NMEA to file on SD card
    if (fileOpened) {
        sdfile.write(c);
        if (++byteCount >= 1024) {
            // flush to file every 1KB
            sdfile.flush();
            byteCount = 0;
            recDataKB++;
        }
    }

    if (!fileOpened) {
        fileOpened = openSDFile();
        if (!fileOpened) {
            delay(2000);
        }
    }
}

It compiles but I dont really know if it works.

I dont really know if it works

Why don't you come back when you've tried it?

I will but I need to know if its written correctly

If it compiles, then as far as the compiler is concerned, it's correctly written.

If it runs and it produces the expected results, it's correctly written.

belink1:
It compiles but I dont really know if it works.

Then I suggest you test it and find out. Why would you NOT test it?