[icon ] blenderdumbass . org [icon scene] Articles

C Programming Language is an Interesting Experience

August 04, 2026

👁 6

https://blenderdumbass.org/do_login : 👁 1

#c #programming #clang #gcc #python #c++

License:
Creative Commons Attribution Share-Alike

[avatar]by Blender Dumbass

Aka: J.Y. Amihud. A Jewish by blood, multifaceted artist with experience in film-making, visual effects, programming, game development, music and more. A philosopher at heart. An activist for freedom and privacy. Anti-Paternalist. A user of Libre Software. Speaking at least 3 human languages. The writer and director of the 2023 film "Moria's Race" and the lead developer of it's game sequel "Dani's Race".


11 Minute Read



I just wrote a functional program in C. It is not doing anything too fancy. But I'm so happy about it because of what it means. For the longest time I didn't know pretty much nothing except of Python. I can use Python for a lot of very interesting stuff. But I want to be able to look at code written in different languages and know what I'm looking at. I want to be able to make changes to the UPBGE game engine for my game Dani's Race and stuff. ↩ Reply

I know, I know, UPBGE is a fork of Blender and therefor is written in C++, not C. What am I wasting my time, learning C, for? Well... ↩ Reply

If C++ is a fork of C, with extensions on top of what C can do. I should understand the difference between the two, I suppose. And therefor I should, first of all, have some idea of what it is like to program in C. ↩ Reply

Here is a surprising thing about this whole endevour. I started looking into C today. And already while writing my first program journal, which I will be talking more in depth about in this article, I already felt like I know the language enough to solve little annoyances and overall code rather quickly in it. It felt almost like writing python code. ↩ Reply

C has modules, kind of like python. In python you import modules using import. Say you want to have access to the operating system functions. You can write something like this: ↩ Reply

import os




And it will give you the whole os modules to do things with in the operating system. ↩ Reply

In C you #include them instead. ↩ Reply

#include <stdio.h>




This stdio.h file is a C code file ( as far as I understand ) that exists somewhere relative to the compiler. And the code of that file is injected into your code. So it is a bit different in practice. ↩ Reply

In python to call a function from os I would be formatting it like this os.getcwd() or something. In C all the functions in the files you include are dumped straight into the same context as everything else. ↩ Reply

For example stdio.h has a function called printf() useful to print stuff into the terminal. It is not stdio.printf() or anything stupid like that. You are just simply using printf() directly. ↩ Reply

I imagine what a pain in the ass this must be for large projects. You have to keep track of so many names. And not, by mistake, define a function with a name that already exist somewhere, in some library you want to use for some task. ↩ Reply

Another strange thing about C is that you must have a main() function where the main execution thing of your code is done. ↩ Reply

In python you just type away. A "hello world" program in python is very simple: ↩ Reply

print("hello world")



In C print does not exist and you have to define a main() function. So in C a "hello world" program is a bit more complicated: c:0 ↩ Reply

#include <stdio.h>
int main() {
    printf("hello world\n");
}




Funny, I wrote this example rather fast for this article. I'm still rather shocked how quickly I'm getting to the point where I can use C for things. And I did double-check myself. This code compiles and outputs an identical output to the python code above. ↩ Reply

Now you can spot a few differences of approach. First the inclusion of the \n thingie in the C version. printf unlike python's print doesn't end every line with a new-line character. You have to specifically tell it to do so. Then there is the ; after each operation. This is because C is indentation agnostic. In python the white-space stuff, like indentation and new line characters, are used to separate stuff, not just visually, but functionally. In C you have visible marks that separate code. Like the ; sign after every operation. I needed time to get used to this. ↩ Reply

Variables are simple but not simple. In python you have so many types of data. You have int for integers and float and floating point numbers and str for text and list and dict and tuple and other various interesting, useful things. In C you have almost none of it. ↩ Reply

You've got your int and float and stuff. And you've got stuff like char which represents a single character of text. ↩ Reply

Now you can do something like this: ↩ Reply

char text[256];




which will be similar to doing something like: ↩ Reply

text = ""



in python, But notice a few things. First you have to specify that it is a char type. Then you can do many char at once, kind of like a list in python, to store some characters-long strings of text. But you have to specify how many of those characters long, this object is. I think in the real world it literally allocates 256 bytes of RAM ( in this example ) for my text string. And running out of this space might cause all sorts of issues. ↩ Reply

Also comparing strings isn't simple either. ↩ Reply

When I was playing around with the language I wanted to make a simple if statement. I input some text and if the text I input is one thing, I do one thing, and if it is something else I do another thing. ↩ Reply

I tried doing this: ↩ Reply

if ( text1 == text2 ){ dosomething(); }



But even though it never errored out, it never worked either. ↩ Reply

Apparently I must do this instead: ↩ Reply

#include <string.h>
if ( strcmp(text1, text2) == 0 ){ dosomething(); }
c:1


The string.h file has the strcmp() function I can use to compare texts. And if the texts are the same, it will return 0. So I need to compare the output of this function to 0. It is a bit annoying. ↩ Reply

In any-case, I decided to write something useful. Writing something useful is always a good stepping stone into learning a language. ↩ Reply

Just a few days ago I wrote a simple GTK program in Python to keep track of my weight. It basically records data I drop at it into a JSON and then shows it to me in a way that makes sense to the task. ↩ Reply

So I thought, okay... how hard would it be to read and write a JSON in C? Ah... I found this. And the size of this whole thing made me feel wrong. And then I found another something to do with C and JSON and the way they described doing it made me feel un-easy. ↩ Reply

See, because C doesn't have a dict like python, making a JSON like structure of data inside of a C program becomes a pain in a butt. ↩ Reply

I decided, fuck it. What is the simplest shit I can do? Well maybe something like a journal writing program. Every entry is a line in a .txt file. All you need to do to present it, is just to printf the whole file. And it is probably doable. ↩ Reply

I present to you journal.c ↩ Reply

#include <stdio.h>
#include <string.h>



int help() {

  printf("\n\n");
  printf("          HELP DIALOGUE of JOURNAL\n");
  printf("\n");
  printf("    help - Print this helps message.\n");
  printf("    save - Saves a text into the journal.\n");
  printf("    show - Prints out the entire journal.\n");
  printf("\n\n");
    

}

int save(char string[]) {

  FILE *data;
  data = fopen("journal.txt", "a");
  fprintf(data, "\n%s", string);
  fclose(data);


}
int show() {

  FILE *data;
  data = fopen("journal.txt", "r");
  char string[1024];

  printf("\n\n");
  
  while( fgets(string, 1024, data) ){
    printf("%s", string);
  }
  
  printf("\n\n");

}

int main(int argc, char *argv[]) {

  if (argc == 1 || strcmp(argv[1], "help") == 0) {
    help();
  }
  else if (argc == 3 && strcmp(argv[1], "save") == 0) {
    save(argv[2]);
  }
  else if (argc > 1 && strcmp(argv[1], "show") == 0) {
    show();
  }


}



You can save it as journal.c and run this command: ↩ Reply

gcc journal.c -o journal



to compile it into an executable. ↩ Reply

And then ↩ Reply

./journal help



to see the help of this program. ↩ Reply

Yes this program does system arguments. And you know what. Those are simple. ↩ Reply

int main(int argc, char *argv[]) {



This line defines the main() function, but look what it also does, it gives it arguments. What? System arguments are built-in in C? ↩ Reply

The argc variable contains the amount of arguments and the argv is a list of lists of characters. A list of text strings. A list of the arguments themselves. ↩ Reply

So from that point it becomes kind of simple. If there are no arguments or the second argument is help ( because the first one is the name of the program ./journal ) we run the help() function. Or in code: ↩ Reply

if (argc == 1 || strcmp(argv[1], "help") == 0) {
    help();
  }




And if you look into the help() function. It is just a bunch of printf(). ↩ Reply

Then if the argument is show we open the file and dump its content into the terminal. Now that is not quite as simple as you think. ↩ Reply

The fun part was to realize that fopen() is like either built-in or a part of the other stuff I already imported. So opening and saving files is actually not that big of a problem in C. ↩ Reply

But the code to dump a file into a terminal is strange: ↩ Reply

  FILE *data;
  data = fopen("journal.txt", "r");
  char string[1024];

  printf("\n\n");
  
  while( fgets(string, 1024, data) ){
    printf("%s", string);
  }
  
  printf("\n\n");



There is a FILE datatype apparently. Python has something similar. Not unlike python's read() C has fgets(). But because the string you are saving to has a certain pre-specified buffer size ( in the case of this code 1024 bytes ), you are reading the file one chunk at a time. And as I have noticed, one line at a time too. ↩ Reply

So while in python it would look like this: ↩ Reply

print("\n\n")

data = open("journal.txt", "r")
print(data.read())

print("\n\n")



in C we need to do a while loop and read the data until there isn't any. Which is a bit weird. ↩ Reply

Also you can't printf() a string directly. You need to append it like that printf("%s", string). What? ↩ Reply

On top of that it seems like C doesn't have much error handling at all. I can open a nonexistent file. And it will just have zero bytes in it. Instead in python it will error out. ↩ Reply

So yeah. It was fun. I know enough C to write pointless bullshit in it now. And to, hopefully, understand more complex code written in it. ↩ Reply

My next challenge. C++. Let's do it. Let's go! ↩ Reply

Happy Hacking!!! ↩ Reply

[icon unlike] 4
[icon right]
[icon terminal]
[icon markdown]

Find this post on Mastodon

[avatar]  Troler c:0 August 04, 2026


In C print does not exist and you have to define a main() function. So in C a "hello world" program is a bit more complicated:
⤴ View

And... your code is going to segfault, you did not provide a return statement.

... replies ( 1 )
[avatar]  Blender Dumbass c:2 August 04, 2026



@Troler I compiled it and tried it and it worked. So apparently it is not that needed.




[icon reply]
[avatar]  Troler c:1 August 04, 2026


if ( strcmp(text1, text2) == 0 ){ dosomething(); }
⤴ View

I would write the code as

if ( !strcmp(text1, text2) ){ dosomething(); }



This is more in style of C, that is, less readable.

... replies ( 1 )
[avatar]  Blender Dumbass c:3 August 04, 2026



@Troler lol




[icon reply]
[avatar]  Blender Dumbass c:2 August 04, 2026


... c:0
[avatar]  Troler c:0 August 04, 2026


In C print does not exist and you have to define a main() function. So in C a "hello world" program is a bit more complicated:
⤴ View

And... your code is going to segfault, you did not provide a return statement.


@Troler I compiled it and tried it and it worked. So apparently it is not that needed.

... replies ( 1 )
[avatar]  Troler c:4 August 04, 2026



@blenderdumbass That's because the compiler adds it for you. main() is an int function, it requires to return an whole number. Here, the number represents the return code.




[icon reply]
[avatar]  Blender Dumbass c:3 August 04, 2026


... c:1
[avatar]  Troler c:1 August 04, 2026


if ( strcmp(text1, text2) == 0 ){ dosomething(); }
⤴ View

I would write the code as

if ( !strcmp(text1, text2) ){ dosomething(); }



This is more in style of C, that is, less readable.


@Troler lol

[icon reply]
[avatar]  Troler c:4 August 04, 2026


... c:2
[avatar]  Blender Dumbass c:2 August 04, 2026


c:0

@Troler I compiled it and tried it and it worked. So apparently it is not that needed.


@blenderdumbass That's because the compiler adds it for you. main() is an int function, it requires to return an whole number. Here, the number represents the return code.

... replies ( 1 )
[avatar]  Blender Dumbass c:6 August 04, 2026



@Troler Well I'm greatfull the GCC isn't stupid.




[icon reply]
[avatar]  Robert Kist 🇦🇹🇩🇪 c:5


@blenderdumbass the nice thing about both C and Python are that they are nice, concise languages, that yet have a great amount of depth. Now C++, well, there's also all that sprawl...

[icon reply]
[avatar]  Blender Dumbass c:6 August 04, 2026


... c:4
[avatar]  Troler c:4 August 04, 2026


c:2

@blenderdumbass That's because the compiler adds it for you. main() is an int function, it requires to return an whole number. Here, the number represents the return code.


@Troler Well I'm greatfull the GCC isn't stupid.

[icon reply]
[icon question]











[icon articles]C Programming Language is an Interesting Experience

[thumbnail]

[avatar]  Blender Dumbass

👁 6 ❤ 4 🔄 1 💬 7



I just wrote a functional program in C. It is not doing anything too fancy. But I'm so happy about it because of what it means. For the longest time I didn't know pretty much nothing except of Python. I can use Python for a lot of very interesting stuff. But I want to be able to look at code written in different languages and know what I'm looking at. I want to be able to make changes to the UPBGE game engine for my game Dani's Race and stuff.


I know, I know, UPBGE is a fork of Blender and therefor is written in C++, not C. What am I wasting my time, learning C, for? Well...


#c #programming #clang #gcc #python #c++


[icon articles]Dani's Race and notgit.py ( Updater )

[thumbnail]

[avatar]  Blender Dumbass

👁 33 ❤ 4 🔄 1 💬 4



Not so long ago I decided to forgo the wisdom of using git for this game. Instead, most changes will be recorded via the notgit.py program I wrote for fun the other day.


#danisrace #moriasrace #game #gamedev #freesoftware #blender3d #git #python #programming #hacking


[icon articles]With AI you are focusing on the wrong Fear of Missing Out

[thumbnail]

[avatar]  Blender Dumbass

👁 33 ❤ 4 🔄 1 💬 8



Vibe-Coders, people that use LLMs for programming, are found at a such high levels of stress these days, that they end up in a hospital over it. They believe that they need to keep up-to-date on everything regarding the endless AI updates, to the point that it literally deteriorates their health. We all know a person in some field that feels like they would not necessarily want to use AI, but in the same time, they don't want to "fall behind" the rest. That they must know how to "use" these tools, or else they will have no chance what so ever, in the market-place. The problem is, they are focusing on the wrong Fear. Especially when it comes to the market-place.


#ai #vibecoding #aiart #microsoft #microslop #aislop #stopai #programming #fomo #art #movies #cinema #cinemastodon


[icon articles]Why you should care about Dani's Race?

[thumbnail]

[avatar]  Blender Dumbass

👁 24 ❤ 3 🔄 1 💬 4



Dani's Race is a pretty to look at, open-world game. Is this a good enough reason to care about it? No. It's not. There are plenty of good looking games out there. And Dani's Race is not even close to some of them. Dani's Race is a Libre "GTA Clone". Okay... so what? It's not the only one. And it is not even that GTA-like anyway. Yes, you can get in and out of cars. Yes, you have an open world. Yes, the levels are structured into missions. But so what? Why should you give a damn? What's so special about this game in particular? Well...

Let's start with a square.



#danisrace #moriasrace #game #gamedev #freesoftware #blender3d #python #programming #gta #gta5 #gtav #gta6 #gtaiv #gtasa #gtavicecity #gta3 #stupertuxkart #libregaming #zeroad #supertux #tux #gnu #linux #gnulinux #opensource


[icon articles]Winning Dani's Race ScoreBoard on WINdows

[thumbnail]

[avatar]  Troler

👁 39 💬 6



I want to get the scoreboard working on Dani's race, but I'm using Winblows operating system. That means a lot of things are broken. That's because Dani's race was developed for the Tux operating system.


#danisrace #moriasrace #game #gamedev #freesoftware #blender3d #python #windows #leaderboard #programming #hacking


[icon articles]Making Breakable Cars in Video Games

[thumbnail]

[avatar]  Blender Dumbass

👁 201



We all love some mayhem when it comes to playing games. And nothing makes car games more satisfying than damage models. RockStar Games understood it early on, and all GTA games have breakable cars. Today some of the most popular car games like BeamNG.drive holding on a realism of damage models almost solely. And therefor for me, making Dani's Race any other way, would have not been a good idea. I knew I had to make the cars in my game breakable.


#DanisRace #MoriasRace #Game #Gamedev #UPBGE #blender3d #animation #GTAClone #programming #project #cars #damage #Gnu #Linux #Freesoftware #OpenSource


[icon codeberg] Powered with BDServer [icon python] Plugins [icon theme] Themes [icon analytics] Analytics [icon email] Contact [icon mastodon] Mastodon
[icon unlock]