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.

  • whotookkarl@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    3
    ·
    2 hours 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

  • Camille@lemmy.ml
    link
    fedilink
    arrow-up
    5
    ·
    6 hours 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 :)

  • e8d79@discuss.tchncs.de
    link
    fedilink
    arrow-up
    7
    ·
    8 hours 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.

  • ShawiniganHandshake@sh.itjust.works
    link
    fedilink
    arrow-up
    14
    arrow-down
    1
    ·
    13 hours 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.

    • mrmaplebar@fedia.io
      link
      fedilink
      arrow-up
      4
      ·
      10 hours ago

      I’m totally with you on this.

      C is a fantastic language for people who want to develop for existing C projects. But there are very few reasons to develop new software projects in C today. As such, for anyone learning C, the best first project would probably be whatever existing C project you want to work on.

      Maybe the main exception to that is probably embedded systems stuff for microcontrollers and the like, but I don’t know enough about that space to say whether that is even still the case or whether you’d be better off with something else.

    • ExLisper@lemmy.curiana.net
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      10 hours ago

      There’s still plenty of jobs using C. C has certified compilers and libraries that let you use it in projects with security regulations like automotive. Those project are not moving to Rust or Zig anytime soon. They are also safe from AI (no one will dare doing anything “agentic” in safety critical projects) and with latest investments in the defense sector in Europe I would expect them to grow in the coming years. If I could change career paths today I would definitely consider C. Rust is great but it’s really hard to find a job as a rust programmer.

      • homura1650@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        10 hours ago

        I don’t know about Europe. But the US (or at least the portion of the US federal government I deal with) has been trying to ban us from using memory unsafe languages for as long as I can remember. For us, Rust isn’t replacing C; it is replacing Ada. The only difference is that they have stopped granting exceptions for new code bases in memory unsafe languages.

        • ExLisper@lemmy.curiana.net
          link
          fedilink
          arrow-up
          1
          ·
          9 hours ago

          Yes, they are trying but C still dominates in many parts of industry. After learning C I would definitely start learning Rust but right now you will have way bigger chances of finding a job with C than with Rust.

          • prettybunnys@piefed.social
            link
            fedilink
            English
            arrow-up
            2
            ·
            3 hours ago

            The other side of this coin is C developers are still plentiful whereas folks who know rust are less available.

            If someone knows C and Rust experience I’m hiring them over the others.

  • who@feddit.org
    link
    fedilink
    English
    arrow-up
    5
    ·
    13 hours ago

    How about a network protocol client, like HTTP, DHCP, SMTP, STUN, IMAP, DNS, DHCP, etc?

  • PeeOnYou [he/him]@lemmygrad.ml
    link
    fedilink
    arrow-up
    1
    ·
    12 hours 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.