Any good links for learning C?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wobbly
    Prophet
    • May 2012
    • 2629

    Any good links for learning C?

    Watching threads in the development sub-board is weird for me. I understand maths well enough that sometimes I can half follow what the code is meant to do, but don't know the syntax well enough to properly understand. I've been vaguely telling myself I should learn to code even if it's to just tinker around a bit for fun. Any good links for starting out? I used to be able to program a little in things like Basic, Fortran & Pascal so I'm not a complete coding Newbie (Though I've pretty much forgotten most of what I knew there).
  • Therem Harth
    Knight
    • Jan 2008
    • 926

    #2
    I would recommend shelling out for "The C Programming Language, 2nd Edition" (Kernighan and Richie):


    The coding style it espouses is IMO a little dated; but it is still the best book on programming I know of, both as a tutorial and as a reference.

    If you prefer a free book, I recommend this one:


    There's a PDF version at the link above.

    Obviously, do the exercises. Maybe not so obviously, read other people's code. Angband is not a very pretty codebase at the moment, but it is handy for this.

    Disclaimer: I'm actually a pretty awful programmer.

    Comment

    • mrrstark
      Adept
      • Aug 2013
      • 101

      #3
      Reading a book is great if you can do it.

      I can't do it. It's too abstract.

      I find the best way to learn something like C is to set a small goal I'm interested in, like say:
      - "add a new spell or combat feature to Angband"
      - "change the way that XYZ works"
      - "write a little program that sends me an email reminder when I'm supposed to do that thing I hate doing"
      - w/e you want.

      Have a language reference to look at, follow examples you can find online, and then Google for any problems you run into, usually ending up at some stack exchange page.

      The phrase "Cookbook" is sometimes a good start for example code on how to do something. I started learning C# from the O'Reilly C# Cookbook, coupled with a good reference, though I don't know of a specific book like that for C.

      Comment

      • fizzix
        Prophet
        • Aug 2009
        • 3025

        #4
        Originally posted by mrrstark
        I find the best way to learn something like C is to set a small goal I'm interested in, like say:
        - "add a new spell or combat feature to Angband"
        - "change the way that XYZ works"
        - "write a little program that sends me an email reminder when I'm supposed to do that thing I hate doing"
        - w/e you want.
        This is essentially how I learned C (although I had lots of experience in other languages.)

        Can you get started here? Can you download angband source and compile?

        Comment

        • Nick
          Vanilla maintainer
          • Apr 2007
          • 9634

          #5
          Originally posted by Therem Harth
          Angband is not a very pretty codebase at the moment
          I'm wounded
          One for the Dark Lord on his dark throne
          In the Land of Mordor where the Shadows lie.

          Comment

          • wobbly
            Prophet
            • May 2012
            • 2629

            #6
            Originally posted by fizzix
            This is essentially how I learned C (although I had lots of experience in other languages.)

            Can you get started here? Can you download angband source and compile?
            Will have a go over the weekend. Thanks to all, for the advice.

            Comment

            • Therem Harth
              Knight
              • Jan 2008
              • 926

              #7
              Originally posted by Nick
              I'm wounded
              I was talking about the pre-refactor code...

              Edit: OTOH let's be fair, I wouldn't recognize "pretty" code if it wore flowers and a bow-tie.

              Comment

              • Nick
                Vanilla maintainer
                • Apr 2007
                • 9634

                #8
                Originally posted by Therem Harth
                I was talking about the pre-refactor code...
                Oh, I agree then, that was garbage

                *runs and hides from rest of devteam*
                One for the Dark Lord on his dark throne
                In the Land of Mordor where the Shadows lie.

                Comment

                • the Invisible Stalker
                  Adept
                  • Jul 2009
                  • 164

                  #9
                  Learning to program in C is easy. It's learning to debug C programs which is hard. And, of course, learning to write programs that other people can read and debug.

                  In general I agree with Therem Harth on this one: Kernighan and Ritchie is still the way to go. Except perhaps if you're going to be writing code where security is critical. K&R example code is often overly trusting of user-supplied input. I once mentioned this to Brian Kernighan, who told me that they had been aware of that even as they wrote it, but that in the computing environment of the time it didn't seem like a big issue. Fortunately for most of the things I do it still isn't much of an issue.

                  Comment

                  • buzzkill
                    Prophet
                    • May 2008
                    • 2939

                    #10
                    This is what I did.
                    Read C for Dummies.
                    Download an IDE.
                    Started writing simple programs.
                    Googled anything I didn't feel like looking up in a book.
                    Worked for me, though I'm nowhere near good enough to delve into a "band" and have since moved onto other interests.
                    www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012.
                    My banding life on Buzzkill's ladder.

                    Comment

                    • the Invisible Stalker
                      Adept
                      • Jul 2009
                      • 164

                      #11
                      Originally posted by buzzkill
                      Started writing simple programs.
                      That was the case for me as well, and probably for most people, but in retrospect I think I would probably have been better off working on pieces of a large program. I got a lot of good, and some bad, advice early on, but on a very small project the difference between the two is often not obvious. I guess what I'm trying to say is, learning C by working on Angband would have been a lot better than starting with "hello world".

                      Comment

                      • Antoine
                        Ironband/Quickband Maintainer
                        • Nov 2007
                        • 1010

                        #12
                        In my experience the hardest thing is downloading the environment, and the project, and getting the environment to compile the project successfully, and then uploading any changes you may make to the project.

                        Once you can do that, the rest is pretty easy.

                        A.
                        Ironband - http://angband.oook.cz/ironband/

                        Comment

                        • Nivim
                          Apprentice
                          • Jan 2014
                          • 69

                          #13
                          You people and your "environment"s and "IDE"s.[/curmudgeon] Don't those have a tendency to hide things from you and so are really bad to start with? :/

                          Comment

                          • buzzkill
                            Prophet
                            • May 2008
                            • 2939

                            #14
                            When I say IDE, I really mean compiler. I write code in Notepad++. If my IDE does other stuff, I'm largely unaware of it.
                            www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012.
                            My banding life on Buzzkill's ladder.

                            Comment

                            • AnonymousHero
                              Veteran
                              • Jun 2007
                              • 1393

                              #15
                              Originally posted by Nivim
                              You people and your "environment"s and "IDE"s.[/curmudgeon] Don't those have a tendency to hide things from you and so are really bad to start with? :/
                              Not really, IMO. The old style text-editor is so far behind in many respects that you're really just reducing your productivity by not using an IDE. Especially symbol lookup and "find usages" style functionality is immensely improved for C++ code in IDEs that actually understand the code (not just on a superficial level as in "ctags"). This has been the case since Clang integration became a thing for C/C++ IDEs. My current favorite is QtCreator, but I mostly work in C++, so YMMV.

                              Comment

                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎