Skip to main content

Command Palette

Search for a command to run...

Day 91/100 100 Days of Code

Jumping Ball

Published
1 min read
Day 91/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.

I began working on retrieving the results from the mini-app. First, I created a new struct:

struct Results
{
    double maxHeight;
    double timeToMaximumHeight;
    double timeToLand;
};

Then, I used the resource locator to find the mini-app's location. This will be used to run the mini-app when the start button is pressed. The FindResource function returns the complete path to the directory or file.

miniApplication.location = FindResource("/Contents/Resources/modules/jumpcalculations");

After that, I had a lot of trouble starting the application. Using the printf function, I discovered that the textboxFont was not being loaded because fontResource.location is being mutated after use. I do not know why. It might be worth opening an issue on SDL_TTF GitHub.

printf("%s\n", fontResource.location); // This is the correct one
char *temp = calloc(strlen(fontResource.location), sizeof(char));
strcpy(temp, fontResource.location);
appFont = TTF_OpenFont(fontResource.location, 30);
TTF_SetFontStyle(appFont, TTF_STYLE_BOLD);

printf("%s\n", fontResource.location); // This is not the correct one, the string gets mutated after use?
textboxFont = TTF_OpenFont(temp, 50); // copying the path to another variable works fine.
TTF_SetFontStyle(textboxFont, TTF_STYLE_BOLD);

It might be a good time to learn some basics of multithreading with C. I plan to use it to run the mini application and make the main thread wait until the calculation is finished.

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.