Search code examples
cfile-iopebble-watchcloudpebble

How do I read from file using pebble c?


I have tried using a function that would work in "regular" c:

const char* getfield(char* line, int num)
{
    const char* tok;
    for (tok = strtok(line, ";");
        tok && *tok;
        tok = strtok(NULL, ";\n"))
    {
    if (!--num)
        return tok;
    }
    return NULL;
}

int main()
{
    FILE* stream = fopen("v1.csv", "r");

    char line[1024];
    while (fgets(line, 1024, stdin))
    {
        char* tmp = strdup(line);
        printf("Field 3 would be %s\n", getfield(tmp, 3));
        // NOTE strtok clobbers tmp
        free(tmp);
    }
}

I am trying to read a file names "v1.csv" located in my pebble app resources folder.


Solution

  • You can not read/write to files, use file descriptor or any of the f* functions in the Pebble SDK.

    If you want to store data on the watch, you should look into the Persistent Storage API.