Learning C from a background in 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开发者_如何学JAVA 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?
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).
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!
I'll answer you question, but first: Going from C# to C is like going from a plastic toothbrush to a wooden one... I see no advantage.
So:
Namespaces - No, there aren't any in C. This is a C++/C# feature. You should be able to compensate with prefixes. (namespace_myClass).
As for classes, I don't know how to help you. I am a C++ programmer (not C), but C does have struct, though I don't know if you can have member functions.
Header files and includes are syntactically the same. For example:
#include <Windows.h>
gives you windows functionality. Note that, you may need to link in libraries for many header files, like openGL.
And what will we do without string? You could make your own, or you can manually manage C strings (char*) with the C functions such memcpy, ect...
Farewell and goodluck!
C++ is a superset of C. So anything you can do in C, you can do in C++.
I think it is a good idea to learn C. It will make you have to deal with memory and resource management, structured programming vs object-oriented, a it has a much smaller standard library as well (compared to C#).
http://publications.gbdirect.co.uk/c_book/
http://www.coronadoenterprises.com/tutorials/c/c_topics.html
http://www.cyberdiem.com/vin/tutorials/
try the above links
精彩评论