tags:

views:

641

answers:

6

Is there some sort of "Learning C for developers of other languages" book or tutorial available?

I am currently trying to learn C (not C++, maybe later) and even though I had some experience with it (had it in school writing DOS Applications using Borland C...), I don't know much about the standard library or about the "architecture".

My current project - which I want to use to learn - is to write an Ogg Theora player. That is, using the libogg, libvorbis and libtheora in my project. But here I already have a problem: How do I link them?

I am a C# developer, and in C# I would just add a reference and be fine. But in Visual C++ (the compiler/IDE that I will use in any case because the project that I really want to do much later depends on an existing C Visual C++ project), I am simply overwhelmed with the project properties.

I did find a lot of resources about C, but much stuff is really basic stuff (explaining what functions are - I know what a function is, I'd just like to know how a function can differ between C and C#/Java) or really academic (the kind of stuff I would read to get sleep, but not to learn something from it).

I found this book useful, but I am also looking for something more concise aimed at existing C#/Java/PHP/Whatever developers, and also about using Visual C++ 2008.

Any good hints?

+3  A: 

Assuming you have precompiled versions of those libraries available (i.e., .lib files, plus a bunch of .h files with the interface). Go into Project Properties, and select Linker\General from the tree on the left. In "Additional Library Directories", add path to wherever those .lib files are in. Then move to Linker\Input, and list all .lib files in "Additional Dependencies". That should take care of the linking.

For header files, you'll need to go to C/C++\General, and add the directory they're in to "Additional Include Directories". Then you can just #include them as usual.

Pavel Minaev
Thanks, that helped. So .lib means a static library that can be compiled as part of my own code, as compared to a .dll which is a dynamic link library that lives outside of my application. In any case, I always need .h files? (I have them in this case, just asking to confirm that they are always needed to work with .lib the proper way)
Michael Stum
Pavel Minaev
+1  A: 

I liked Kernighan and Ritchie (K&R) for learning C after I had taken most of my classes in college in Pascal I thought it made it an easy transistion.

From Basic, Pascal, Assembly, and a spattering of various classes in "Programming Languages" class. K&R was easy reading, and concise, and should be the first book in most C programmer's libraries.

NoMoreZealots
+1  A: 

Another convenient way of linking to other libraries from your project is to just add the .lib files you want to link as an existing item in the solution explorer. The IDE will know that you want to pass them to the linker. That way you do not need to add the path and the file name in separate places in the linker settings.

On learning C, most classic (like K&R) are very much geared towards using the standard C library in a POSIX environment. If you want to write C programs on windows you will also need to get into the Win32 APIs, especially if you want to write a multimedia application. http://msdn.microfost.com is your most promising starting point for samples and tutorials on any of the APIs you might need to use for that.

Writing a GUI with plain C on Win32 is a world of pain that you probably don't want to go through. You might want to ask for advice here on choosing a lightweight native Win32 UI library with a plain C (not C++) interface.

VoidPointer
+1  A: 

In addition to Pavel Minaev's answer, I often find it useful to create property sheets (.vsprops) to easily define a specific dependency.

For example, if I depended on libX, I could make a libX.vsprops file and place the exact include path, lib path and .lib files I require into the property sheet. That one property sheet can then be used across configurations and/or projects, thus saving you the trouble of updating multiple configurations when something changes.

You can find more information about property sheets on MSDN.

Warning: Property sheets are only saved when you close the solution! They are NOT saved when you do a "Save all", either manually or when you start a build.

Soo Wei Tan
+1  A: 

If you can understand french, there is a good tutorial right here.

It explains the basics, but also the more complex stuff.

Live
+2  A: 

Why don't you use something that's more lightweight and simpler to use than visual Studio for your C Projects?

I reccommend Code::Blocks. Believe me, it's a lot more lightweight than Visual Studio, and in my opinion it's a lot better to work with it whilst learning to develop in C.


As regards books, I would go for both K&R's C Programming Language, but I also reccomend another one : C Primer Plus and I think the latter one is more appropriate as a beginner's book.

Andreas Grech