Skip to main content

Command Palette

Search for a command to run...

Day 97/100 100 Days of Code

Jumping Ball

Updated
1 min read
Day 97/100 100 Days of Code
C

AKA Chris, is a software developer from Athens, Greece. He started programming with basic when he was very young. He lost interest in programming during school years but after an unsuccessful career in audio, he decided focus on what he really loves which is technology.

He loves working with older languages like C and wants to start programming electronics and microcontrollers because he wants to get into embedded systems programming.

Back to working on the results of the mini-app. I had trouble getting the results because strtod always output a value of 0.0. I tried atof, but the same problem occurred. I then tried creating my own functions for char* to double conversion and accidentally discovered what the problem was.

The getResult function was getting the correct value, but there was an issue with strtod(). While building my own conversion, I discovered that using &getresult[0] printed the correct value. I decided to use this instead of getResult alone, and now everything works!

for (int i = 0; i < 3; i++)
{
    char *characterLoc = strchr(tempCopy, ',');
    size_t index  = (size_t)(characterLoc - tempCopy);
    char *toCopy = calloc(strlen(tempCopy) - index, sizeof(char));
    char *getResult = calloc(index, sizeof(char));
    strncpy(getResult, tempCopy, index);
    strncpy(toCopy, tempCopy + index + 1, strlen(tempCopy )- index);
    tempCopy = toCopy;
    char *endString;

    switch(i)
    {
        case 0:
            //results.maxHeight = atof(&getResult[0]);
            results.maxHeight = strtod(getResult, &endString); 
            break;
        case 1:
            //results.timeToMaximumHeight = atof(&getResult[0]);
            results.timeToMaximumHeight = strtod(getResult, &endString);
             break;
        case 2:
            //results.timeToLand = atof(&getResult[0]);
            results.timeToLand = strtod(getResult, &endString); 
            break;
    }
    free(getResult);
}

Also, I tried to fix the remaining segmentation faults, but I couldn't resolve all of them. The issues have been reduced, but they still exist.

100 Days of Code

Part 1 of 50

100 days of code is a good initiative to go into hard mode and spend more time in programming. These 100 days will be focused on completing projects and research.