VOGONS

Common searches


First post, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

Hello. Just looking for some guidance about learning to program in C in the 2020s.

I believe I will need a book about programming in C and it is the best way to get exposure to programming in C by topic. Am I right?

Is it possible to find example programs to work on that teach C in any other form?

I have one guide I am reading now that is showing me topics like pointer arithmetic, pointer-array equivalence, and accessing structure members with pointers. But the information is given to me with no real world program to examine.

Do I need to go to a school where an instructor assigns you a book and a project?

How can I find the exercises and Example Programs I need online?

I have to be careful not to look at anything so complex I can't be expected to learn anything given my level of understanding is as a beginner.

Thanks

Reply 1 of 24, by TheMobRules

User metadata
Rank Oldbie
Rank
Oldbie

IMO everyone that seeks to learn C should get "The C Programming Language", by Brian Kernighan and Dennis Ritchie, aka "K&R". It's not very long, it's beginner-friendly and clearly explains all the fundamental concepts of the language with plenty of examples and exercises.

Moreover, one of the authors (Ritchie) is the creator of C so that's another aspect that gives this book it's "C Bible" status.

Just get the simplest compiler you can get (something like Turbo C on DOSBox) and you can get started right away, avoid complex libraries and abstractions or UI stuff at the beginning if you're trying to learn the language.

Reply 3 of 24, by Ensign Nemo

User metadata
Rank Oldbie
Rank
Oldbie
serialShinobi wrote on 2024-05-01, 19:25:

I believe I will need a book about programming in C and it is the best way to get exposure to programming in C by topic. Am I right?

I'm of the strong opinion that a good book is the best way to learn something in detail, regardless of the latest trends or fads. If you really want to learn a subject inside out, there aren't many substitutes. If that's your goal, then I would look for a good book. However, if you want to get started quickly, you probably don't need to dive right in to a deep book, at least not as your main way of learning. I would either look for a more recent, concise book or for online tutorials (text ideally). The latter can be especially helpful if you want to copy and paste something (some books will come with code that you can download). A lot of people will recommend taking an online course from somewhere like Coursera or YouTube videos. While these can be helpful as an introduction, video as a medium often prevents the teacher from going into detail. I've worked with a number of people who taught themselves machine learning or statistics from an online course like Coursera, and, in my opinion, they often are unfamiliar with key concepts that would be covered in any competently written book. Another drawback is that video isn't great if you lose attention for a bit or don't quite understand something. It can be a bit of a hassle if you need to go back and rewind the video. Even if you're watching the video on a good computer that doesn't buffer much, it can still be hard to go back to a part if the teacher is just talking for awhile. You have to listen for whatever verbal queue you're searching for, but also limited to the speaker's talking speed. On the other hand, it's a lot easier to skim through a book or webpage if you need to go back to something. One exception would be if you need to do something like customize your IDE's GUI. It's often way quicker to watch someone demonstrate it on YouTube than reading the documentation that describes it.

Personally, I think that a good book will complement another, more concise approach. It's important to both read and get started with simple programming at the same time. That's similar to how many university courses are taught. You will have a book and will be required to read certain pages or chapters each week. At the same time, you will have computer labs where you will do programming assignments.

One thing that is often overlooked is the documentation for the language itself. A lot of books, courses, or tutorials will give you an introduction to a concept and provide a few examples. However, this doesn't do a great job of teaching someone how to look up for themselves how to do something. This is important because a tutorial might teach you 90% of what you need to know to create the program you're working on, but that remaining 10% is going to be the hardest part. It's extremely valuable to become comfortable looking up stuff in the official documentation. When you first start looking at the documentation after doing a few tutorials or a short course, actual documentation can seem overwhelming and the format may seem like nothing you saw in your lessons. Nonetheless, it is extremely helpful if you need to figure out what exactly you can do with certain data structures for example. I haven't touched C in nearly 20 years, but I use Python and R regularly. Here's what it looks for in Python:

https://docs.python.org/3/library/stdtypes.html#typesmapping

Here's the documentation for GNU C for example:

https://www.gnu.org/software/gnu-c-manual/gnu … al.html#Preface

serialShinobi wrote on 2024-05-01, 19:25:

Do I need to go to a school where an instructor assigns you a book and a project?

No, but a school program has two or three main advantages. First, you will have a teacher (and likely a teaching assistant) to ask for help. While valuable, there are plenty of knowledgeable people who will help answer questions online. Second, a school program gives you an organized schedule with goals and deadlines. I think this by far the most important advantage that a school program offers. Most people don't have the discipline to keep up with the work required to learn a programming language. They will typically do well at first, but work and life gets in the way. Obviously, there are many self-taught programmers, so it can be done, but you need to be very disciplined. With a school course, you will need to meet deadlines in order to pass. This means that you will need to put in the hours, even if you are tired and rather take the evening off. Personally, I had to do a bunch of all-nighters when I took my programming courses. I hate doing that, but with deadline approaching, you don't always have the option.

There could be a third advantage, depending on what you want to do with this. If it's for work, having credentials might matter for a potential employer. Some employers might be fine if you have an impressive portfolio, but other might expect credentials.

Apart from your questions, I think that having projects in mind is a huge motivator. Ideally, you would have some fun projects in mind that you could work on as you learn the language. This goes back to the motivation part of learning a language. Simply following tutorials can end up being a bit boring after awhile. However, having something fun to motivate make the difference between sticking with it or not. If you have no project in mind right now, you could look at some of the online projects that provide problems for you to tackle.

Here's a mathematical oriented one:
https://projecteuler.net/

If you're interested in biology, you could try these:

https://rosalind.info/problems/locations/

Reply 4 of 24, by EduBat

User metadata
Rank Newbie
Rank
Newbie

I also recommend "The C Programming Language", by Brian Kernighan and Dennis Ritchie, "the 2nd edition".
Before the language was standardised in the ISO standards, I remember someone telling me that C compiler writers used this book as their guide.

Reply 5 of 24, by llm

User metadata
Rank Member
Rank
Member
serialShinobi wrote on 2024-05-01, 19:25:

How can I find the exercises and Example Programs I need online?

using google as for everything on the internet - for example: "github c examples beginner"

many not super-trivial but more "practical" examples: work youself through these - refere to the specific github project file if you got questions
https://github.com/gouravthakur39/beginners-C … rogram-examples

more trivial stuff
https://github.com/h0mbre/Learning-C

...and a trillion more

the internet is all you need - absolutely everything is explained there - im comming from a time were Internet wasn't existent at all - i do not understand how todays people got problems in finding information at all 😀
- there seem to be many people out there that are not familiar with googles search power - very strange

prevent using ChatGPT as a tutor - https://www.iguazio.com/glossary/llm-hallucination/ - it can be very distracting for newbies to get examples that sound super correct but containing micro bugs - not needed in your stage of learning
especially when not able to see hallucination easily

and be more concret in your posts: people already started again to give you tips what compiler,IDE you should use - thats fixed now - and you need to state that - there are so many developers around here with so many ideas and tips when you
ask - it won't get you any faster to ask 10 more people 😀

Reply 6 of 24, by Ensign Nemo

User metadata
Rank Oldbie
Rank
Oldbie
llm wrote on 2024-05-02, 05:57:

using google as for everything on the internet - for example: "github c examples beginner"

llm wrote on 2024-05-02, 05:57:

the internet is all you need - absolutely everything is explained there - im comming from a time were Internet wasn't existent at all - i do not understand how todays people got problems in finding information at all 😀
- there seem to be many people out there that are not familiar with googles search power - very strange

I'm going to respectfully disagree here. It's not always so simple just to Google something. The sheer number of results can be overwhelming and, worse yet, the top hits are often poor quality, especially for programming tutorials. I have started just going straight to Stack Exchange or a Stack Overflow site whenever I need to look for programming help because the top Google hits are usually low quality blog posts that just copied another site. Google has also been getting progressively worse and it's becoming harder to find something that was written by an actual knowledgeable person instead of some search engine optimized site that was scraped together to get clicks.

Another problem is that people don't always know what to search for. K&R C has been brought up here, and a newbie might not have even known about it. Another thing is that it's often just fun to ask a question here because it starts a discussion. Some people prefer to ask a question here that they could find the answer to elsewhere because they enjoy interacting with other people here.

Reply 7 of 24, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

I recommended the K&R C programming language book way back in the original thread but the OP wasn't interested in it.

It's the best intro to the language for a reason. The author(s) being responsible for the language itself as well as Unix is just one of them.

My collection database and technical wiki:
https://www.target-earth.net

Reply 8 of 24, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
megatron-uk wrote on 2024-05-02, 11:40:

I recommended the K&R C programming language book way back in the original thread but the OP wasn't interested in it.

I've had a change of heart. I intend to start reading any book that's current and that isn't specifically for experienced programmers. Planning to look for the latest "The C Programming Language" by Kernighan & Ritchie. However I have seen this book before and it seems like it doesn't go into the depths that modern books about C go into. It is just a hunch but I believe it is from a time before javascript & python were prevailing scripting languages. C was used by developers to make advanced software but books like K&R were a reference for systems administrators in need of an advanced scripting language. And that was the audience for K&R. But I will look at it again. Maybe it does go into more depth than just keywords and functions. Or some reference/encyclopedia treatment of pointers and arrays. I will check again because it has been awhile since I read K&R. But just for now I say that I believe things have changed. C is no longer a scripting language for system administrators. It now takes its place with those who need to write applications. Anyone learning C now needs to be taught to use it for development of advanced software.

Reply 9 of 24, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
Ensign Nemo wrote on 2024-05-01, 23:48:
I'm of the strong opinion that a good book is the best way to learn something in detail, regardless of the latest trends or fads […]
Show full quote

I'm of the strong opinion that a good book is the best way to learn something in detail, regardless of the latest trends or fads. If you really want to learn a subject inside out, there aren't many substitutes. If that's your goal, then I would look for a good book.
...

One exception would be if you need to do something like customize your IDE's GUI. It's often way quicker to watch someone demonstrate it on YouTube than reading the documentation that describes it.

...

Personally, I think that a good book will complement another, more concise approach. It's important to both read and get started with simple programming at the same time.

Thanks for explaining those differences between books and the pros/cons of books and other sources and their strengths/weaknesses. I will definitely take this to heart.

Reply 10 of 24, by TheMobRules

User metadata
Rank Oldbie
Rank
Oldbie
serialShinobi wrote on 2024-05-02, 12:32:
megatron-uk wrote on 2024-05-02, 11:40:

I recommended the K&R C programming language book way back in the original thread but the OP wasn't interested in it.

I've had a change of heart. I intend to start reading any book that's current and that isn't specifically for experienced programmers. Planning to look for the latest "The C Programming Language" by Kernighan & Ritchie. However I have seen this book before and it seems like it doesn't go into the depths that modern books about C go into. It is just a hunch but I believe it is from a time before javascript & python were prevailing scripting languages. C was used by developers to make advanced software but books like K&R were a reference for systems administrators in need of an advanced scripting language. And that was the audience for K&R. But I will look at it again. Maybe it does go into more depth than just keywords and functions. Or some reference/encyclopedia treatment of pointers and arrays. I will check again because it has been awhile since I read K&R. But just for now I say that I believe things have changed. C is no longer a scripting language for system administrators. It now takes its place with those who need to write applications. Anyone learning C now needs to be taught to use it for development of advanced software.

I’m not sure where you got the idea that C was intended as a “scripting language for sysadmins”, but it’s completely wrong. C always was a compiled language, even historically it was closely related to the development of UNIX. Every modern operating system (Windows, Linux, etc.) is still mostly written in C!

The book goes as deep as it needs to go as it’s a complete description of the language, again not sure where you are taking the “just keywords and functions” from.

And no, C has not recently taken its “place with those who need to write applications”. It’s a lower level language than JavaScript or Python (and much older than both of those) and nowadays it’s mostly used to develop things that require a more direct access to the underlying hardware, such as device drivers or embedded software. It’s purpose in modern development doesn’t overlap with JS or Python which are intended for different things. But it was always a general purpose compiled language and you can do anything with it if you want.

Reply 11 of 24, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

So although C is a language that is pre-compiled before it's execution, one of the books I have, seems to run the C source straight from the command line - just like a script. That's what meant. Yes there was a time when C was used for system administration purposes...before one could easily do it with python, javascript, visual basic, other scripting languages, etc.

The book I am referring to is the mother of all short examples. He just hits ./{name of program}.c and right there in the console and then you see output. So for a typical hello world example in C source - ./hello.c - output: hello world.

The people who use Unix here should be able to clear this up. Not saying C is compiled Just-in-Time (JIT). But I am saying it can easily be repurposed to be used in a way that is like a scripting language to take care of day to day problems in the Unix environment.

I'm saying in this book it appears as if one can change the permissions of *.c to executable and then use ./ to execute said *.c -UNIX implicitly compiles the *.c (source) and executes in the console thus showing output. That's very comparable to a script if it is true, right down to just in time compilation of source into executable binary code.

Reply 12 of 24, by Error 0x7CF

User metadata
Rank Member
Rank
Member

Unix may have done that at some point, it certainly doesn't now. A similar effect can be achieved using TCC in a script though, as so:

(contents of helloworld.sh)

#!/usr/local/bin/tcc -run
#include <stdio.h>

int main()
{
printf("Hello World\n");
return 0;
}

commandline:

./helloworld.sh

As a side note, shell scripts are *absolutely not* just-in-time compiled, they're an interpreted pseudolanguage that the shell binary (sh, bash, zsh) understands.

K&R C is almost certainly the book you want. It is indeed old but the core of C has basically not changed since it was properly specified in the ~1989 ANSI C, which the revised edition is conveniently about. It has as much depth as you'd want about the language itself. Anything more would be compiler-specific or platform-specific.
I don't see what the relevance of the rise of JavaScript/Python/etc to learning C is, at all. If you want to learn C it is the same as it always has been.

Old precedes antique.

Reply 13 of 24, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
Error 0x7CF wrote on 2024-05-02, 14:56:

Unix may have done that at some point, it certainly doesn't now. A similar effect can be achieved using TCC in a script though, as so:

...

I don't see what the relevance of the rise of JavaScript/Python/etc to learning C is, at all. If you want to learn C it is the same as it always has been.

Ok. So, in the book I was reading it is likely the author was using simple examples in C that were being interpreted by the shell binary on a UNIX host.

I was mentioning java script and scripting languages because at one time they were not used much or even had not been invented. So when writers teaching the C language would write about the language for an audience of people who used shell scripts to achieve tasks to manage a UNIX server.

But I'll have to study K&R to many people are telling me that it is essential. It must be anything but an encyclopedia. More like a serious treatment of how the language really works.

Reply 14 of 24, by pancakepuppy

User metadata
Rank Newbie
Rank
Newbie

I enjoy "C: A Reference Manual" by Harbison & Steele. The 5th edition is very easy to find online in PDF format. Covers differences in C99, C89, and neanderthal C, lots of syntax examples and practice questions to test your knowledge.

Reply 15 of 24, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

Forget about Unix, forget about scripting languages, just-in-time compilation and everything else.

Just get the K&R book, a compiler (literally any), and start working through some basic exercises.

The compiler and tool chain should be largely irrelevant and replaceable by another compiler on another platform if you stick to the standards.

My collection database and technical wiki:
https://www.target-earth.net

Reply 16 of 24, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
pancakepuppy wrote on 2024-05-02, 18:38:

I enjoy "C: A Reference Manual" by Harbison & Steele. The 5th edition is very easy to find online in PDF format.

I just read a couple of sentences about types and I am blown away. I was so excited I had to put [my phone] down because there were other people around me and I couldn't contain myself. It looks like a good book. It is hard to find good books.

Reply 17 of 24, by llm

User metadata
Rank Member
Rank
Member
serialShinobi wrote on 2024-05-02, 21:08:
pancakepuppy wrote on 2024-05-02, 18:38:

I enjoy "C: A Reference Manual" by Harbison & Steele. The 5th edition is very easy to find online in PDF format.

I just read a couple of sentences about types and I am blown away. I was so excited I had to put [my phone] down because there were other people around me and I couldn't contain myself.

typical when reading this book - sometimes people will aplaud around you and start crying tears of happiness 😀

Reply 18 of 24, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
llm wrote on 2024-05-03, 07:29:

typical when reading this book - sometimes people will aplaud around you and start crying tears of happiness 😀

Yes. I should have told them I found a great book. They probably would have been happy for me.

Reply 19 of 24, by myne

User metadata
Rank Member
Rank
Member

I've done a bit of the python course here: https://www.codecademy.com
It's fairly bite sized lessons and it has a... kind of fake machine for you to write and run code in so there's no messing around with IDEs etc.
However, I have been paid to code in a different language, so I guess I'm a professional even if I feel like an imposter half the time.

Here's the C course. It's free so it can't hurt to check it out.
https://www.codecademy.com/catalog/language/c

Things I built:
Mechwarrior 2 installer for Windows 10/11 Re: A comprehensive guide to install and play MechWarrior 2 on new versions on Windows.
Dos+Windows 3.11 auto-install iso template (for vmware)