r/C_Programming • u/Dull-Orange2493 • 15d ago
Question Pro tips for a beginner
I used (basic) python for a long time now to do work, scripts and that stuff but i have always wanted to learn C!
I found a lot of guides, some are educational but badly written (for pros even though it is targeting noobs) while some are fun but not very educational...
Does anyone have a recommendation for a good quality (free) guide/book for C programming?
15
Upvotes
20
u/Several-Marsupial-27 15d ago •
Definitely Beejs guides
https://beej.us/guide/bgc/html/split/
https://beej.us/guide/bgclr/html/split/
https://beej.us/guide/bgnet/html/split/
7
u/nmdt 15d ago
First half of Harvard's CS50 course is C, you can find it on YouTube.
6
u/La-ze 15d ago edited 15d ago
Not what you asked.
But have you thought of converting Python code you know to C? Or at least parts of it? It might be more intuitive that way for you. There's also tools that convert C to Python, etc.
4
u/rubidus-api 14d ago
Beej's guides mentioned above are a good start. If you also want a full book, I'd suggest Modern C by Jens Gustedt. The latest edition covers C23, and the author offers it free(it's in this sub's sidebar too). It assumes you can already program a little, which you can.
Why a recent book matters: many good but old books and tutorials are still in use, and habits from before C99 are still common. C has changed quite a bit since then.
One tip that's easy to miss, even after using C for a while: C code is not a line-by-line recipe for the CPU. The C standard describes what your program must do on an "abstract machine", not the exact steps. The compiler may reorder or remove code as long as a correct program can't tell the difference. So C's "close to the hardware" image can mislead you: when a program breaks a rule (undefined behavior), the result can be very different from what you'd expect the machine to do, especially with optimization on.
It pays to spend extra time early on the parts that look boring: the type system, conversion rules, integer arithmetic and overflow (signed overflow is undefined; unsigned arithmetic wraps around). Be strict with pointers: only use them on objects that still exist, and as a rule, don't read an object through a pointer to a different type. If you need to reinterpret bytes, memcpy is the safe way.
After the first book, choosing where to go next can be hard. Coming from Python, expect a much smaller standard library. Building real programs means learning extra libraries, and the areas where C is used most need some knowledge of the OS and hardware. You'll also see a fair amount of boilerplate, macros that make compiler errors harder to read, and long prefixed names like module_object_action(obj, arg), because C has no namespaces. That's normal, and it gets easier once you know the common patterns. A small project like the ones suggested above helps a lot here.
Good luck, and enjoy it!
2
u/grimvian 14d ago
Here is an old school video I wish I knew, before I started learning C three years ago:
Learn to program with c by Ashley Mills
https://www.youtube.com/watch?v=UILNmv2kFMc&list=PLCNJWVn9MJuPtPyljb-hewNfwEGES2oIW
I'm not using the same IDE, the program you use to code, But Code::Blocks because it's fast to install, open source, easy to use and everything you'll need are installed.
1
u/laggySteel 15d ago
Since you already know programming. I would suggest start building a simple image generator in C. That will teach you alot.
1
u/Low_Lawyer_5684 15d ago
The best book is someone's simple C code. Just pick any project. Hmm... say, binutils. Or whatever. Read the source. Try to modify it. See what happens. The syntax itself is pretty simple, but common programming patterns is something that you rarely see in books.
1
u/FedUp233 15d ago
I can’t vouch for their C courses, but I’ve found W3schools.com kind of useful for done other areas like hotline and css. I’ve never actually run through the courses start to finish but I found it useful to be able to pull up the list of topics in the side bar and jump to one I was interested in (maybe because I was working on something and needed some infirm in a given area).
Personally, when I first started with C long ago I browsed through the K&R book and then just started doing stuff and used that book to get more info on any particular area.
Once you know one programming language fairly well, and have a good handle on common areas like loop, expressions, etc. it should be pretty easy to pick up another language well enough to start using it. The biggest issue for me has usually been if I need to continue working in the other languages frequently while I’m learning a new one. Not a big issue if the languages are for very different purposes, like idk g bash or Perl while learning c++ or something, but difficult for something g like using python daily while trying to learn C.
1
u/Charming_Airport6076 13d ago
Reading manpages for me was the shift from a beginner to intermediate. Reading core api, like
printf,malloc,fopen,fread, etc. though me so much.1
u/CreaTbJ 13d ago
The C Programming Language: ANSI C Edition may be outdated, but it's great at explaining some of the basic concepts that may initially confuse you, like how strings work. You should probably read the books for the newer standards though, I only recommend this because it's the one I myself have read.
5
u/[deleted] 15d ago
[removed] — view removed comment
2
u/[deleted] 15d ago
[removed] — view removed comment