how should i deal with two appvars?
close and reopen
 100%  [ 2 ]
combine into one appvar
 0%  [ 0 ]
Total Votes : 2

I tried doing ti_Open() on more than one app var at a time. Only the last one was opened and its pointer was assigned to all other appvars. I believe this is normal after looking at the src code, but I am not too sure, as my assembly knowledge is very bad.

Also, if this is the case to access two appvars should i just simply close whenever i don't need it and open it again or should I just make the two appvars into one and use ti_Seek with an offset? I made the data into different appvars as a form of organization but tbh its not really necessary.
That shouldn't happen. What does your code look like?
Its a bit wonky, but I just edited the example code for fileioc/read_write with some funky code (I don't think this is the right way to use two appvars):

Code:

#include <tice.h>
#include <fileioc.h>

int main(void)
{
    char nameBuffer[10];
    ti_var_t var;
    char string[] = "AppVar string";
    ti_var_t var2;
    /* Clear the homescreen */
    os_ClrHome();

    /* Open a new variable; deleting it if it already exists */
    var = ti_Open("AppVar", "w");
//extra
    var2 = ti_Open("Ao", "w");



    if (var == 0)
    {
        return 1;
    }
//extra
    if (var2 == 0)
    {
        return 1;
    }
    /* Write characters to the appvar */
    if (ti_PutC('a', var) == EOF)
    {
        os_PutStrFull("Failed character");
        while (!os_GetCSC());
        return 1;
    }

    /* Write the structure to the appvar */
//extra
    ti_Write(string, sizeof(string), 1, var2);
    if (ti_Write(string, sizeof(string), 1, var) != 1)
    {
        os_PutStrFull("Failed string write");
        while (!os_GetCSC());
        return 1;
    }

    /* Go back to the start of the file */
    if (ti_Rewind(var) == EOF)
    {
        os_PutStrFull("Failed rewind");
        while (!os_GetCSC());
        return 1;
    }

    /* Read character from the appvar */
    if (ti_GetC(var) != 'a')
    {
        os_PutStrFull("Failed character read");
        while (!os_GetCSC());
        return 1;
    }

    /* Read string back to same location */
    if (ti_Read(string, sizeof(string), 1, var) != 1)
    {
        os_PutStrFull("Failed readback");
        while (!os_GetCSC());
        return 1;
    }
//extra
    if (ti_Read(string, sizeof(string), 1, var2) != 1)
    {
        os_PutStrFull("Failed readback");
        while (!os_GetCSC());
        return 1;
    }

    /* Ensure the name of the AppVar is correct */
//makes nameBuffer ao instead of AppVar
    ti_GetName(nameBuffer, var);

    /* Ensure that the slot is closed */
    ti_Close(var);
    ti_Close(var2);
    var = 0;

    os_SetCursorPos(0, 0);
    os_PutStrFull("Appvar: ");
    os_SetCursorPos(0, 8);
    os_PutStrFull(nameBuffer);
    os_SetCursorPos(1, 0);
    os_PutStrFull(string);

    /* Waits for a key */
    while (!os_GetCSC());

    return 0;
}



try on your emulator. it could be also a problem with my emulator after I messed around with all the features, but I don't think thats a problem.
You're never rewinding var2. As a result, you're trying to read starting from the end of the appvar, not the beginning.
I don't think that was the problem. The output claims that the value stored in nameBuffer is Ao, which in reality should be AppVar.

Can you show me a working example where you open two appvars and read from them without closing until the end?

Code:
#include <tice.h>
#include <fileioc.h>

int main(void)
{
    char nameBuffer[10];
    ti_var_t var;
    char string[] = "AppVar string";
    ti_var_t var2;
    /* Clear the homescreen */
    os_ClrHome();

    /* Open a new variable; deleting it if it already exists */
    var = ti_Open("AppVar", "w+");
//extra
    var2 = ti_Open("Ao", "w+");



    if (var == 0)
    {
        return 1;
    }
//extra
    if (var2 == 0)
    {
        return 1;
    }
    /* Write characters to the appvar */
    if (ti_PutC('a', var) == EOF)
    {
        os_PutStrFull("Failed character");
        while (!os_GetCSC());
        return 1;
    }

    /* Write the structure to the appvar */
//extra
    ti_Write(string, sizeof(string), 1, var2);
    if (ti_Write(string, sizeof(string), 1, var) != 1)
    {
        os_PutStrFull("Failed string write");
        while (!os_GetCSC());
        return 1;
    }

    /* Go back to the start of the file */
    if (ti_Rewind(var) == EOF)
    {
        os_PutStrFull("Failed rewind");
        while (!os_GetCSC());
        return 1;
    }

    /* Go back to the start of the file */
    if (ti_Rewind(var2) == EOF)
    {
        os_PutStrFull("Failed rewind");
        while (!os_GetCSC());
        return 1;
    }

    /* Read character from the appvar */
    if (ti_GetC(var) != 'a')
    {
        os_PutStrFull("Failed character read");
        while (!os_GetCSC());
        return 1;
    }

    /* Read string back to same location */
    if (ti_Read(string, sizeof(string), 1, var) != 1)
    {
        os_PutStrFull("Failed readback");
        while (!os_GetCSC());
        return 1;
    }
//extra
    if (ti_Read(string, sizeof(string), 1, var2) != 1)
    {
        os_PutStrFull("Failed readback");
        while (!os_GetCSC());
        return 1;
    }

    /* Ensure the name of the AppVar is correct */
//makes nameBuffer ao instead of AppVar
    ti_GetName(nameBuffer, var2);

    /* Ensure that the slot is closed */
    ti_Close(var);
    ti_Close(var2);
    var = 0;

    os_SetCursorPos(0, 0);
    os_PutStrFull("Appvar: ");
    os_SetCursorPos(0, 8);
    os_PutStrFull(nameBuffer);
    os_SetCursorPos(1, 0);
    os_PutStrFull(string);

    /* Waits for a key */
    while (!os_GetCSC());

    return 0;
}
This is the result after I run your code:


as you can see it displays Appvar: Ao instead of Appvar: Appvar
Appvar: Ao is correct. Read the code again.
It will produce the same result even after changing ti_GetName(nameBuffer, var2); to ti_GetName(nameBuffer, var); Try running the code yourself. For some reason var and var2 point to the same thing. I don't know if its a problem with my program or if its a bug.
Hey Mateo, if you have time, can you look into my problem? Thanks.
For future reference the issue was caused by not updating libraries.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement