Day 92/100 100 Days of Code

Day 92/100 100 Days of Code

Jumping Ball

I kept working on getting the results. I had some trouble with crashes but it has been fixed now. The GetResults function now generates the correct system command.

void GetResults(char *location, char *value)
{
    struct Results results;
    char *commandPartFirst = "cd ";
    char *commandPartSecond = "&& fpm run -- ";
    char *command = calloc(    strlen(location) + strlen(value) + strlen(commandPartFirst) + strlen(commandPartSecond), 
                                                    sizeof(char));

    strcpy(command, commandPartFirst);
    strcat(command, location);
    strcat(command, commandPartSecond);
    strcat(command, value);

    int getSystemInfo = system(command);
    printf("%d\n", getSystemInfo);
}

Also, I updated the main function to generate the correct command for the CSV file located within the application and moved the InitApp function to the top of the main.

nt main(void)
{
    if (!InitApp())
  {
        exit(EXIT_FAILURE);
    }

    double startTick = 0, endTick = 0, frameTime = 0;
    char *temp;
    size_t currentStringSize = 0;
    Uint32 mouseState;
    bool quit = false;
    SDL_Event events;
    char *testCommand = "test -f ";
    char *fileLocation = "app/output/calculations.csv";
    char *createCommand = calloc(strlen(testCommand) + strlen(miniApplication.location) + strlen(fileLocation), sizeof(char));
    strcpy(createCommand, testCommand);
    strcat(createCommand, miniApplication.location);
    strcat(createCommand, fileLocation);
    int getCalcFile = system(createCommand);

    free(createCommand);

  if (getCalcFile == 0)
  {
        char *cdCommand = "cd ";
        char *removeCommand = " && rm calculations.csv";
        createCommand = calloc(strlen(miniApplication.location) + strlen(cdCommand) + strlen(removeCommand), sizeof(char));
        getCalcFile = system(createCommand);
        free(createCommand);

        if (getCalcFile != 0)
        {
            printf("Calculations CSV removal failed\n, %d", errno);
            exit(EXIT_FAILURE);
            }
  }

The strings in C are very complicated but interesting at the same time. Next, I need to update the GetResults function to be able to read the CSV file.