Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning C from a background in C#

Tags:

c

I want to broaden my programming experience and so figured that learning C (not C++) would be a nice idea - I've got a starting project (some simple 2D games using SDL) and given it a go, but I have to admit I'm struggling.

Now I consider myself to be a very a competent C# developer, but C is just a completely different world!

  • No namespaces.
  • Without classes I don't know how to structure my code.
  • I understand header files & includes, but my use of them doesn't seem quite right.
  • The loss of (for example) the String class is a bit of a culture shock.

On top of that I'm finding it tricky to separate out the C++ information from the C information (for example is snprintf a C++ only thing?)

This may sound like an odd request, but are there any good guides for learning C if you have experience in other languages?

like image 516
Justin Avatar asked Oct 23 '10 04:10

Justin


People also ask

Can I learn C after C#?

There are many good reasons to move from C# to C. All embedded programming is done in C. As a lower-level language it helps you learn more about OS and hardware. Taking on the additional privileges and responsibilities of C is good programming experience.

How can I start learning C language?

Get started with C. Official C documentation - Might be hard to follow and understand for beginners. Visit official C Programming documentation. Write a lot of C programming code - The only way you can learn programming is by writing a lot of code.

Is C tough to learn?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

Don't try to learn C from C++ books/web sites. Start with something aimed only at C. A great place is The C Programming Language. It's the original and still one of the best programming language books out there.

Learning C is going to be a struggle because it's a different kind of language. It's a procedural language, not an object oriented language. It will be good to stretch your brain in learning it. You'll likely also learn a lot more about the way your OS works because it's down much closer to the metal.

Note also that it's a much less complex language and thus is missing a lot of the niceties of a modern language. There is no BCL/.Net Framework. As you noticed, there is no string class (although there are string functions).

like image 178
Steve Rowe Avatar answered Sep 26 '22 19:09

Steve Rowe


I'd recommend you start with a book on C. It's not a good idea to learn a new language in constant comparison with a previous one, you end up learning what's different and not what's new and unique.

Take a look at Kernighan and Ritchie's book, or Deitel & Deitel's. They will both strike you as overly basic at first, but you'll end up with a much more solid knowledge of the language.

edit: a friend of mine right here suggests you also find something on data structures and algorithms after you've grasped the language, since you'll be working in an environment with no objects.

Hope it helps!

like image 34
slezica Avatar answered Sep 26 '22 19:09

slezica