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.

If this is the wrong place to ask this question, please let me know.

I'm a Python programmer by occupation. I would love to learn C. Indeed, I have tried many times, but I always get discouraged. In Python, you write a few lines and the program does wonders. In C, I can't seem to be able to do anything useful.

It seems to be very complicated to even connect to the Internet.

Do you have any suggestions on what I can do to learn C? Are there are any good websites? Any cool projects?

Thanks

share|improve this question

closed as off-topic by MichaelT, GlenH7, World Engineer Sep 16 '13 at 22:16

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

  • "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." – MichaelT, GlenH7, World Engineer
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
It is nice to be able to stand on the shoulders of genius isn't it. The Python interpreter is written in C. Now you have a true appreciation for what the designers really did. It is pretty fing amazing. –  Pemdas Feb 27 '11 at 2:10
    
@Pemdas C is normally used for creating system programs. –  Searock Feb 27 '11 at 7:52
    
Might I recommend starting out by reading the contents of a file, and possibly doing some basic transformation into another file? Example: Take a CSV and parse it into a tab-delimited file. Alternately, you could learn how to read header information out of a BMP of JPEG image file. –  Joshua Burns Aug 31 '12 at 21:31
    
I'm to late to add an answer, but there's this online C for Python Programs booklet. Also, the makers of "Learn programming the hard way" are making a book called "Learn C the Hard Way", which is aimed at people who already know a bit of python or similar. –  naught101 Feb 22 at 12:17
add comment

7 Answers

up vote 24 down vote accepted

Don't get discouraged.

Python is a high-level programming language. In comparison to C, it can produce wonders in a tiny amount of code. Don't start by trying to mimic Python results in C - you'll be promptly disheartened. Programming in a C requires a different style of thinking and understanding because as you're interacting with the computer at a more intimate level. Here's a good starting point for learning C:

Books

Online Material

share|improve this answer
1  
Can you suggest a programming exercise? Something useful preferably. Thanks. –  Honza Pokorny Mar 1 '11 at 1:02
add comment

If you want to learn C, don't start with connecting to the Internet. You can do that in any other language. That's not what's most important in C.

Instead, take a look at pointers, arrays, references, structs in this C Tutorial. This will help you understand memory management and many of the features that "bring you closer to the machine."

If you can learn and understand this material, then look into expanding into a possible project. These concepts are fundamental to any real professional C programming.

This Pointer Tutorial looks helpful as well.

share|improve this answer
add comment

It is very complicated to connect to the internet! Think about it:

  • Your computer might have multiple ways of connecting -- WLAN, Bluetooth, Ethernet, etc. Each of those has its own settings, which you need to set. You're lucky that there's already standards and drivers for these... using these could be a lot harder than it already is right now.

  • IP addresses can be IPv4 or IPv6, and you need to be able to handle both.

  • There may or may not be proxies configured for the system.

  • You have to support FTP, HTTP, or some other protocol.

  • You might need to use dial-up, so you have to specify a phone book with passwords and phone numbers, if you're not already connected. Ditto with WLAN usernames/passwords.

  • You might need to work with cookies.

  • The system might cache some data, so do you want to use the cache or not?

and the list goes on and on.

So the fact that it's easy to do these with Python necessarily means that a lot of these are hidden from you (or difficult to set), so you trade simplicity for power. The C library is the opposite: it has all the power you need (you can easily perform system calls), but doesn't have any defaults (or, in fact, any features for connecting to the internet).

Instead of thinking of C as being tedious, think of it as being powerful. But in any case, don't try to connect to the internet with it -- that's a pretty darn hard thing to do. Instead, start learning how to use the library for more basic tasks (e.g. file I/O), learn about how pointers and arrays really work, and when you learn all those, then try tackling big projects. You'll appreciate Python more that way too. :)


Edit:

I personally suggest that, if you have free time, learn C# first instead. As soon as you get comfortable with it, start learning about the unsafe keyword and how to use pointers and do marshaling in C#. You'll still have a really big library to work with, like with Python, but you'll be able to do a lot of things that you can do in C. Then transition into calling system API's manually (like InternetOpen), and learn how to get those to work. You'll still have a lot of flexibility but you'll get a great introduction to lower-level concepts. After you've done these, then start learning C -- then you'll find it to be a piece of cake, and you'll see (C? get it?) the advantages and disadvantages of high-level and low-level languages, and you'll be able to find the one that suits your needs.

That said, I think A Crash Course in C might be useful as a starting point to jump into the sea C.

share|improve this answer
add comment

Don't read kernel code when you're learning C. It's full of tricks to squeeze every last bit of performance out of it. Some of it is very non-standard. It'll drive you crazy.

Instead, take a look at a few smallish, high code quality projects:

  • Lua - If you're not interested in programming languages, you may want to skip this one. Otherwise, it's truly beautiful code and amazing to see how much they accomplish with so little (something you seem frustrated by since you're coming from Python).
  • ZeroMQ - I love this project. It's a light-weight, super-fast message queue. Again, high quality stuff.
  • DarkHttpd - A 2700 line web server in C. Covers a few fun topics like socket programming, parsing, and working with protocols.
share|improve this answer
add comment

One purpose of a higher high level language is to hide complicated things. If you want to learn a "lower" level language, and don't want to start with really complicated things (that were formerly mostly hidden from you); try starting with some simpler learning projects, sorting an array of numbers, or reversing a string of characters, or some such...

It's easier to go up a steep hill by taking small steps.

share|improve this answer
add comment

As far as cool projects to look at: Unix kernels are written in C.

share|improve this answer
    
Did you mean to add a link? –  jmort253 Feb 27 '11 at 2:42
add comment

Learn C grammar first , and then use it to write data structure and algorithm. Of course you can read Linux kernel as you expert c language.

share|improve this answer
add comment

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