Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

That's right, I learned to program in C++, and of course know the common set of features of both languages, so I can program in C.
But I'd really like to read tutorials or books that teach you C, and the C way of programming, from a C++ programmer's perspective.

share|improve this question

closed as off-topic by gnat, Kilian Foth, MichaelT, GlenH7, Robert Harvey Apr 8 '14 at 19:56

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions seeking career or education advice are off topic on Programmers. They are only meaningful to the asker and do not generate lasting value for the broader programming community. Furthermore, in most cases, any answer is going to be a subjective opinion that may not take into account all the nuances of a (your) particular circumstance." – gnat, MichaelT, Robert Harvey
  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Kilian Foth, GlenH7
If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers 4

up vote 12 down vote accepted

I think the best way to get started is to go through Kernighan & Ritchie's "The C Programming Language". It's a reference book for C's features and syntax, but pretty much all the examples and sample programs included are very elegant and illustrate the "C way of doing things".

Amazon link: http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

Another good resource you might wanna check is http://c-faq.com/. It answers most of the common questions about the language.

After that you just need to take a look at some C programs and write a couple on your own, preferably playing with the trickier parts of the language (i.e., pointers, pointers to functions, memory allocation, etc.).

share|improve this answer
Thanks, but I already use pointers, pointers to functions and memory allocation, as I wrote, I know C++ already. And also already read K&R –  Petruza Dec 6 '11 at 16:44
I believe there are some differences in the way you use those, though. For instance, C's malloc returns a pointer to void and returns NULL on failure, while C++'s new don't do either, so you might need to use them differently depending on the program. –  daniels Dec 6 '11 at 16:46
I've tried, it seems the more advanced C programming level they have, the more they like to obfuscate their code in obscure macros almost impossible to track down to actual code. :D –  Petruza Dec 6 '11 at 16:50
@Petruza If you read K&R, just sit and do your work. The most significant difference between C and C++ is that in C++ you constantly learn how to make use of its great features and in C you just... do the programming. –  mbq Dec 6 '11 at 19:28
@daniels: The main difference is that C++ programs rarely, if ever, use new directly. –  DeadMG Dec 7 '11 at 7:09

there are ways to synthesize a lot of C++ features in C. even though you may not actually want to do this, I found it highly educational. Check out the C++ FQA (literally FQA, not FAQ ) by an anti-C++ curmudgeon ( a highly intelligent one at that!). He talks about foward-declaring functions that accept structures in C, then linking to their implementation later on. This is similar to the idea of C++ polymorphism. You can learn alot about something by seeing its equivalence to other things.

share|improve this answer
He may be intelligent, but he's definitely poorly informed and illogical. Most of his arguments boil down to "C++ is bad because I wish it were different." –  Jerry Coffin Dec 6 '11 at 16:19
true, but I learned a lot about C++ from reading his anti-C++ manifesto. It was good to hear a strongly concocted anti-C++ argument. –  Timmah Dec 6 '11 at 18:44
I went through a random section of the FQA once. It was a mixture of ignorance of C++ itself, ignorance of how to use it, and personal preferences made up to be anti-C++ and ranted on as if they were basic principles. Read the C++ FAQ Lite instead; it covers the same areas and does it well. –  David Thornley Dec 7 '11 at 17:12

Becoming C++ programmer from C quiet difficult, but the other way round is not so difficult. This is my personal experiance, as i turned a C++ programmer from C. K&R is a great book, the best book i have ever read. I still find it interesting. Advanced Programming in the UNIX Environment, 2nd edition, another great book.

But let me tell you, you will not find useful features like class, exception handling, template etc. But you should always keep them in mind even if you will be in C, as some of them can be achieved with some extra effort.

share|improve this answer
The "some extra effort" is the problem, at least when it's relevant, but I agree that some of the concepts from C++ are still useful in C. Take classes. They're basically parameter blocks with some extra bells and whistles. And like classes, parameter blocks should ideally model some meaningful abstraction. –  Steve314 Dec 7 '11 at 1:03

Speaking as someone who uses C++ every day, but has had to do a fair chunk of C work...

Don't forget what you learnt in C++. You can still do good object oriented design in pure C, you just need to do things a little differently.

I found that sitting down with one of the C libraries that I'd integrated into a C++ application and reading through its source code (rather than just the headers) was really helpful. Though you need to find a well implemented library.

I particularly learnt a lot from lua, freetype2 and libxml2.. but there's heaps of good libraries out there. (Also heaps of bad ones... so if it looks badly engineered, dump it and move on).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.