I have always had a great deal of respect for C, and I would like to start writing in it. However, while I am skilled in other languages, I basically don’t know any C off the top of my head.

I find that I learn better and faster by attempting projects, rather than working through a book ir taking a class. For example, to learn Perl, I am working on a basic disk image writer that’s coming along nicely.

So, what do you think might be a good idea for my first C project?

EDIT: Zig is also something I’m interested in learning. Same question, different language.

  • Camille@lemmy.ml
    link
    fedilink
    arrow-up
    11
    ·
    4 months ago

    Back when I was a student, we had to implement the following projects to validate and I think they are a really nice set of training projects for C (memory management, handling your own types, algorithms and off-by-one traps):

    • a basic implementation of diff
    • a fully functional hashmap (subproject of diff actually)

    I personally wrote the followings too:

    • a program to compress/decompress archives using only the LZ77 algorithm
    • math expression evaluator (i.e. a basic interpreter)
    • a basic garbage collector (mark&sweep, mark&copy, whatever grinds your gears)

    If you are already a competent developer in other languages, these should be reasonable projects. The difficulty lies in doing them in C. For the hashmap, the evaluator and the archiver, you have to correctly manage your data and memory. this makes them excellent projects for learning what makes C… C. For the garbage collector… well… you are the memory manager. Basic GC algorithms are easy to understand but what you want to learn here is the actual management of the memory. See it as a more advanced project if you want to really grok dirty C.

    Most importantly: have fun :)

  • ShawiniganHandshake@sh.itjust.works
    link
    fedilink
    arrow-up
    11
    arrow-down
    2
    ·
    4 months ago

    As someone whose first “real” programming language was C, I recommend against writing anything new in C.

    There are plenty of C projects you could consider contributing to as a way to learn the language (and if you want a long and prosperous career, knowing C can only help you) but language design has come a long way since the 70s and something like Golang or Zig or Rust would get you many of the advantages of C with many fewer pitfalls.

  • e8d79@discuss.tchncs.de
    link
    fedilink
    arrow-up
    8
    ·
    4 months ago

    C is the lingua franca of computing, having a basic understanding of it is in my opinion an essential skill. So I would disregard the recommendations of learning Zig or Rust for now. These languages have their place but they aren’t as entrenched and universal as C. To learn C you could try a few of the exercises on the exercism C learning track. Another good project, to learn a new programming languages in general, is building a calculator that parses an expression like 2 + 3 / (5 - 1) and outputs the result while respecting the correct order of operations.

  • whotookkarl@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    3
    ·
    4 months ago

    You could make a process tree like pstree, something with an easily checked output and fast to test is usually a good starting project

  • monkeyman512@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    4 months ago

    Maybe start by taking an existing script you wrote in another language and hand rewrite it in C? Then you can focus on understanding how things are done differently in C.

  • PeeOnYou [he/him]@lemmygrad.ml
    link
    fedilink
    arrow-up
    1
    ·
    4 months ago

    My first C program beyond hello world was a ‘madlibs’ type game. I wrote up a story and then prompted for adverbs, nouns, adjectives, and then filled them into the story.