what is the best way to learn C ? I know basic python but would like to learn C, I tried searching online but couldn’t find a good resource that’s good for a beginner like me. any suggestions ?

  • thingsiplay@beehaw.org
    link
    fedilink
    English
    arrow-up
    9
    ·
    1 year ago

    There is no single best way for every beginner. When I web search for “how to learn c programming”, then a lot of tutorials will appear. It would be good to know what does make them “bad resource” in your opinion, so one can give a better suggestion. Also it would be good to know what your end goal with C is; systems programming? cli programming? why is Python not enough? do you want work as a C programmer somewhere?

    Read a book about C, follow the examples and try to solve stuff alongside, play with the code. Take your time. And look out that its not too old, as the language and tools changed over time. Here is a suggestion: A complete and up to date open source book as downloadable PDF

    • ShadowCat@lemmy.dbzer0.comOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      I just want to learn the low level stuff about how programs are written in C, and things like how system starts processes, how programs interact with the OS etc, (I guess that’s basically systems programming ?).

      It would be good to know what does make them “bad resource” in your opinion

      some that I’ve looked up seem rather shallow and don’t explain things well, what I’m struggling with is the memory allocation stuff, like what is malloc ? realloc ? calloc ?

      why is Python not enough?

      Python is enough, I’m happy with it; I just want to learn more.

  • Dunstabzugshaubitze@feddit.de
    link
    fedilink
    English
    arrow-up
    6
    ·
    1 year ago

    https://jsommers.github.io/cbook/cbook.pdf

    Might be a good way for someone who is familiar with a higher level language.

    Than there is of course “The C Programming Language” by Ritchie and Kernighan and “advanced programming in the unix enviroment” by stevens and rago.

    So, i’d guess just get your feet wet with small stuff. Find out how to take arguments from the command line, or read a file, maybe programm a simple guess the number game. After you are more familiar with the syntax and so on you could look into using your c code in a higher level language. For python you’d have to look into ctypes for that.

  • I_like_cats@lemmy.one
    link
    fedilink
    English
    arrow-up
    4
    ·
    1 year ago

    Going right from python to C is rough. But you can try. I would suggest watching YouTube tutorials or reading a Book about C

  • TheTrueLinuxDev@beehaw.org
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    1 year ago

    One of the thing I recommends is to start small. Going from Python to C is quite a leap, because C language requires some fundamental computer science understanding when you write codes that offers no railing or safety net when you make mistakes. I would actually suggests that you start with C#, it is very forgiving when you make a mistake and have various tools to help you identify the bug in your program.

    Big part of C# is that there is available video tutorial on an introduction to C# provided by Microsoft and it have subtitles. The biggest reason why I would recommend C# to beginner is simply that they offers a lot of resources to help beginners understand the fundamental of programming in general. They have tons of books, video tutorials, vibrant community, and so forth. Also C# can run on wide range of platforms, Windows, Linux, Mac OSX, Raspberry Pi, and so forth. Once you master C#, you’ll find that a lot of the knowledge you gained from it is transferable to C, C++, Rust, DLang, and so forth.

    • reinar@distress.digital
      link
      fedilink
      English
      arrow-up
      7
      ·
      1 year ago

      C#

      eh… those are fundamentally different, C is not object-oriented so OOD part goes straight out of the window. The only thing similar about them is syntax to some degree (which is really irrelevant), approach is completely different.

      • TheTrueLinuxDev@beehaw.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Yeah, but when someone is completely new to programming, it’s best to start somewhere easy where there are quite a lot of tools to help them fix bugs in code. In C# IDE, it have a lot of visual indicators to help them identify bugs, debugger is pretty comprehensive and integrated, and there are quite a lot of resources to introduce them to programming in forms of videos and documentations and community. The goal of learning C# is not to only program C#, but to get them acquaintances with general programming such as for loop, memory management like using disposal in C#, recursion functions and so go on. They can use C# as a starting point to just basic programming and then once they are comfortable, they can move on to other language that they are curious about.

  • Estinos@lemm.ee
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    1 year ago

    I’ve started learning C four years ago, after a career spent coding ruby/javascript/Go, so I guess I was in the same position than you. I started by reading the GNU C manual, then the Glibc documentation, and the man pages for headers and functions I was using (all glibc functions have a man page ; depending on your distros, it may already be installed or you may need to install a specific package to install them all at once). And of course, reading header files in /usr/include/ is always useful for using this or that library. Later, I discovered the book Modern C and it completed my education to feel at home with C. I can’t say if it’s the best path, but it worked for me.

    • ericjmorey@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 year ago

      Ever since edX had their IPO, I hesitate to call it free. Each edX course is free for a limited time now and their prices are way too high if you aren’t interested in a certificate and the certificates aren’t worth much in the employment market. They need a $50 option for no certificate and “unlimited” course access.

        • ericjmorey@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          That puts a bit of organizational overhead on the learner. The material is all there and organized, but it’s not as conveniently presented nor does it mark your progress automatically. I like that they switched to GitHub code spaces and away from cloud9 which complicated things further.

  • reinar@distress.digital
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    there’s a lot of different C’s out there - I mean coding for microcontrollers looks really different to coding graphics with opengl, for example, especially for a beginner.
    What do you want to do achieve with C specifically?

  • flashgnash@lemm.ee
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Personally I wouldn’t jump straight from python to C, python tends to hold your hand quite a bit and C will absolutely let you shoot yourself in the foot.

    Personally I consider languages like c# and java a middle point but I don’t do C so I’m probably not the best person to gauge that, just have seen a lot of people try and fail to jump straight into C from high level languages

  • samwise@beehaw.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    One thing that I did that was super helpful was to try to replicate something from Python.

    (Yes, I know you can just look at the Python source, but just trying to ignore that and thinking about ways one might go about it. Not for production, just for practice)

    For example, I wanted to try making something akin to Python’s lists in C, with all of it’s various operations, e.g. append, insert, length, split, reverse, copy, etc. I started with a single data type, and then wanted to expand it to accept whatever data type I threw at it. A project like this covered a lot of C concepts and really helped me get a grasp on things like data structures, memory management, search algorithms, etc.

  • Square Singer@feddit.de
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Why do you want to learn C?

    This here might be an A B problem, so I’d like to check what is your goal, before recommending how to get into C. For most use cases there are much better options around nowadays.

    Many of the use cases you needed C for in past decades now have better alternatives.

      • Square Singer@feddit.de
        link
        fedilink
        English
        arrow-up
        4
        ·
        edit-2
        1 year ago

        Tbh, A-B-problems are something super common in IT. So much time is wasted by going down the wrong road because someone comes to you with the apparent solution that they thought of, instead of just posing the problem they want a solution to.

        In case of this post, there are quite a few reason why the OP wants to learn C after learning a bit of Python, and some of them have C as the correct solution, some don’t.

        For example:

        • OP wants to make C-modules for Python -> C is the correct language, though Google might already have a fitting module
        • OP heard that Python is slow and C is fast -> Improve your Python skills, learn algorithmics
        • OP has a legitimate problem to solve where Python is not fast enough -> Check out Java/C#/Rust or, if it really has to be, C++
        • OP wants to program microcontrollers -> C is good, but might want to check out MicroPython
        • OP wants to program games -> Unity + C#
        • OP wants to go real low level -> C
        • OP is a masochist -> C or Assembly

        Especially the “C is faster” argument is often a trap for new programmers, since C is only faster if you really know what you are doing. C can also be much slower if e.g. you mess up memory management. Or, more common, C is not at all, because the rookie programmer gets stuck at arcane error messages that they can’t fix.

        In most cases the pure execution speed is not what is limiting the performance, but instead the algorithms and data structures used. For example, if you loop through a large array to find an entry it doesn’t matter that the looping is 4x the speed, when you could also just use a hashmap/hashset, which will be orders of magnitude faster.

  • visiblink@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I did exactly this last summer. There are some new concepts that take time to grasp (memory management, pointers, etc.). I really benefited from watching Ashley Mills’ tutorials on YouTube, but he makes some major leaps as he goes along, which require you to do some research on your own to figure out.

    As always, having something that you want to program helps, since it provides a motive for learning. My goal was to replicate one of my Python projects in C.

    Here’s a link to the tutorials: https://www.youtube.com/playlist?list=PLCNJWVn9MJuPtPyljb-hewNfwEGES2oIW