PDA

View Full Version : Learning C



dsjas297
November 27th, 2005, 03:23 AM
Hello. I am just starting to learn C, which is going to be my first programming language. Does anyone know of any good tutorials and/or books for C?

YourSurrogateGod
November 27th, 2005, 03:47 AM
Source for all ANSI C functions:
http://www-ccs.ucsd.edu/c/

Some ANSI C tutorials:
http://www.its.strath.ac.uk/courses/c/

A good C programming forum where many folks can help you out:
http://www.codeguru.com/forum/index.php?

By the way, I'd personally recommend that you learn C++ before C, just from personal experience. It'll make object-oriented design easier to understand in the future. Plus it's easier to go from C++ back to C (doing it the other way can be more problematic or so I've read.)

dsjas297
November 27th, 2005, 03:54 AM
Hmmmm...
Well, if you say it is better, I should probably start learning C++ instead. Any good tutorials for that?

YourSurrogateGod
November 27th, 2005, 03:59 AM
Hmmmm...
Well, if you say it is better, I should probably start learning C++ instead. Any good tutorials for that?
The reason why I'm suggesting C++ over C is that C++ will introduce you to newer concepts about programming. Both languages have their use, but I wouldn't recommend using C religiously on every project, especially when C++ can do the trick.

Here (http://www.cplusplus.com/doc/tutorial/) is a good starting tutorial. You can use the same forum that I gave you for programming questions (the people there are nice and will help you out very often, especially to folks that are just starting out, but please don't ask some of the members to do your homework, it is looked down upon.) Also, here (http://www.codeguru.com/forum/showthread.php?t=231039) is a list of some good books about C++ programming.

YourSurrogateGod
November 27th, 2005, 04:03 AM
Here (http://www.fredosaurus.com/notes-cpp/index.html) is also a good C++ resource. And this (http://www.sgi.com/tech/stl/stl_index_cat.html) is a great source on the Standard Template Library (getting info out of it at times might be difficult), but you probably won't need it right away, I'd stash that link somewhere in your bookmarks for future reference. Tools such as STL don't exist in C and you don't get the nice abstraction that classes provide in C++ (after becoming more proficient in both languages, you'll know what I mean.)

Burke
November 27th, 2005, 07:34 AM
Hey, that STL link was exactly what I needed... Thanks!

By the way, if you are serious about C++ programming, you should think about getting a copy of Bjarne Stroustrup's "The C++ Programming Language". This is a very advanced book, but you can extract some information from it at a beginning level. You will never outgrow it, that much it for sure!

Unfortunately, it is prohibitively expensive. My copy (Special edition) was $100CDN (~$85-90USD). You could probably find a used softcover edition for $40 though.

LordHunter317
November 27th, 2005, 09:14 AM
If you're going to really start with C++, read Accelerated C++ or Thinking in C++ (which is free online, but not as good).

But I highly recommend if you really want to learn programming you read Structure and Interpretation of Computer Programs first.

YourSurrogateGod
November 27th, 2005, 03:00 PM
Hey, that STL link was exactly what I needed... Thanks!

By the way, if you are serious about C++ programming, you should think about getting a copy of Bjarne Stroustrup's "The C++ Programming Language". This is a very advanced book, but you can extract some information from it at a beginning level. You will never outgrow it, that much it for sure!

Unfortunately, it is prohibitively expensive. My copy (Special edition) was $100CDN (~$85-90USD). You could probably find a used softcover edition for $40 though.
When it comes to advanced STL C++ stuff, I'd recommend this (http://www.amazon.com/gp/product/0130858501/104-3120220-6653556?v=glance&n=283155&s=books&v=glance) book. I've used it before and love it.

Biased turkey
November 27th, 2005, 07:34 PM
Hello. I am just starting to learn C, which is going to be my first programming language. Does anyone know of any good tutorials and/or books for C?

I generally don't like Sams book, but "Sams teach yourself C++ in 21 days" is imho a very good book.
http://www.amazon.ca/exec/obidos/ASIN/0672327112/qid=1133116392/sr=8-3/ref=sr_8_xs_ap_i3_xgl14/702-0867168-5476063

dsjas297
November 28th, 2005, 12:26 AM
Thanks to everyone, especially YourSurrogateGod, for all your help.

David Marrs
November 28th, 2005, 01:57 PM
I found Sroustrup's book pretty heavy going as a beginner. I wouldn't recommend it to a newbie.

Lux Perpetua
November 29th, 2005, 08:57 AM
I learned both C and C++, and I don't think there's necessarily anything wrong with learning C first. Actually, had I learned C++ first, I think I would have found C very painful (as Fortran 77 was rather painful after learning modern languages). If your main goal is to become a C++ programmer, however, then there may be no advantage to learning C before learning C++.

I wholeheartedly recommend the Sam's Teach Yourself C in 21 Days, which taught me C as a programming newbie.

YourSurrogateGod
November 29th, 2005, 02:46 PM
I learned both C and C++, and I don't think there's necessarily anything wrong with learning C first. Actually, had I learned C++ first, I think I would have found C very painful (as Fortran 77 was rather painful after learning modern languages). If your main goal is to become a C++ programmer, however, then there may be no advantage to learning C before learning C++.

I wholeheartedly recommend the Sam's Teach Yourself C in 21 Days, which taught me C as a programming newbie.
Going from C (a procedural oriented language) to C++ (an object oriented language) is a much more difficult chore than the other way around, generally speaking. All methods that are in C are also in C++ (except it's highly recommended that one uses the newer C++ functions), which allows you to do anything in C++ that you wanted in C and much more.

Also, since you did not have many problems going from C to C++, does not mean that others will not.

pizzach
November 29th, 2005, 03:00 PM
Hello. I am just starting to learn C, which is going to be my first programming language. Does anyone know of any good tutorials and/or books for C?

Agh! The pain that is C!!! I was an avid Java programmer before my engineering courses forced me to learn it suddenly.

C is a beautiful language with how simple it is. It took me a while to get used to its vague compile errors and slightly different syntax though.

I would recommend the good old "The C Programming Langugage (Second Edition)." It's a really good reference book if anything and not expensive. I think it's been around for 20 years with no changes. Has to be doing something right. ;)

David Marrs
November 30th, 2005, 03:05 PM
I love C's simplicity as well. I really enjoyed reading The C Book (http://publications.gbdirect.co.uk/c_book/), which is out of print now, but is reproduced on-line. I think it's the best programming book I've read, actually.

YourSurrogateGod
November 30th, 2005, 03:16 PM
I love C's simplicity as well. I really enjoyed reading The C Book (http://publications.gbdirect.co.uk/c_book/), which is out of print now, but is reproduced on-line. I think it's the best programming book I've read, actually.
Yes, do you have a point, C is very simple, but imo, that's a set-back. You'll have to implement more of the things in C that are normally done for you in C++.

Poel++
November 30th, 2005, 07:54 PM
Hi,

I'm learning C at the moment and i've been encountering some problems. First of all I'd like to say that I've installed the gcc-4.0 and gcc-3.4 on my system as well al libstdc++5 and 6 (the development files only for 6).

Compiling a simple "Hello World" is no problem. Though when I'm compiling a more advanced program, I get a lot of compiling errors and warnings, especially about including some header files. The problem is that the file I'm compiling has been compiled by many other students as well as by myself on a different computer.
Does anyone know what the problem might be?

If you like I can post the source as well as the compiling errors/warnings.

Thanks in advance!

Poel++

YourSurrogateGod
November 30th, 2005, 08:42 PM
Yeh, seeing the source would be helpful. Different compilers compile stuff in different ways.

Wallakoala
November 30th, 2005, 10:32 PM
Accelerated C++ by Andrew Koenig and Barbara E. Moo is a VERY good book. I am learning how to program in C++ and this book is just great. Look it up on amazon.com, there is some good info on it there.

darth_vector
November 30th, 2005, 10:59 PM
i went from C to C++ and i would say that its the better way to go. if you want to learn OO programming then C++ isnt the best place to start. probably python or java would be better.

i would start with C. if you can write a C program then you can write C++ but, but this doesnt work in the other direction.

LordHunter317
November 30th, 2005, 11:50 PM
No, that's not true.

The two languages are different enough in styles you do a major disservice learning C first. Many thing you must do in C are bad form in C++.

Poel++
December 1st, 2005, 09:43 PM
This is what my code looks like, it's fairly basic. I'm writing driver for a COM device. I'm right in the beginning of the process. The two procedures are for loading and unloading the linux kernel module.

-----------------------------------------
#include <linux/kernel.h>
#include <linux/module.h>

int init_module(){
printk("Hello World\n");
return 0;
}

void cleanup_module(){
printk(Goodbye World\n");
}

--------------------------------------------

The errors I get do not concern this code itself. The compiler comments focus on the header files.

e.g.
In file included from lkm.c:2:
/usr/include/linux/module.h:41 error field 'attr' has incomplete type
/usr/include/linux/module.h:49 error field 'kobj' has incomplete type
etc.

As I said before, I recently installed libstdc++v6 as well as its development files...

Can anyone help??

kinds regards,
Poel++

Jengu
December 2nd, 2005, 04:03 AM
(Disclaimer: My opinion follows)

Dear lord that's terrible advice. Don't learn C++ first! :P

If you're being told to learn C++ first, 99% of the time it's someone with little real world C++ experience following tutorials here and there on the net and working with the assumption that C++ is just C with classes. The truth is C++ is radically different in many ways in terms of how you should do things. C++ is technically backwards compatible with C, but most of the time you want to avoid the C way of solving a problem.

C++ is a BEAST of a language. It's enormously complex. Getting over the initial humps of learning programming is bad enough without being beaten over the head with templates, classes, the STL, references, and bizarre inconsistencies of all kinds. C, although lacking object oriented programming facilities out of the box, is at least simple.

Saying that "all methods that are in C are also in C++" is somewhat misleading too. You shouldn't be using any of the standard C methods if you're using C++ because C++ has provided replacements for them. Whether you learn C or C++ first, keeping them in your mind as seperate languages is probably a good idea.

That said, C probably isn't a great first language either. Certainly better than C++ though. Take a look at Python -- it's interpreter is a great learning tool because you can type code in and test what it does without a compile step. But I wouldn't wish C++ as a first language on anyone. I 'knew' C++ before I did my internship this summer, where I coded it 8 hours a day. I now realize how much I didn't know. The sheer number of 'gotchas' C++ has under its sleeve for a newbie programmer makes it a terrible learning language.

rock freak
December 2nd, 2005, 09:04 PM
If your learning C like me at the moment then id say get the book called Practical C(3rd edition tis not as heavy as some of the others and is fairly cheap on amzon.

iots a great book and is really help me alot since i got it all of a week agao hehe :p

YourSurrogateGod
December 3rd, 2005, 02:51 AM
i would start with C. if you can write a C program then you can write C++ but, but this doesnt work in the other direction.
Uhh... no. That's the other way around. With exception for a few things here and there, for the most part going from C++ to C is a cakewalk, the other way around isn't true.

YourSurrogateGod
December 3rd, 2005, 02:54 AM
This is what my code looks like, it's fairly basic. I'm writing driver for a COM device. I'm right in the beginning of the process. The two procedures are for loading and unloading the linux kernel module.

-----------------------------------------
#include <linux/kernel.h>
#include <linux/module.h>

int init_module(){
printk("Hello World\n");
return 0;
}

void cleanup_module(){
printk(Goodbye World\n");
}

--------------------------------------------

The errors I get do not concern this code itself. The compiler comments focus on the header files.

e.g.
In file included from lkm.c:2:
/usr/include/linux/module.h:41 error field 'attr' has incomplete type
/usr/include/linux/module.h:49 error field 'kobj' has incomplete type
etc.

As I said before, I recently installed libstdc++v6 as well as its development files...

Can anyone help??

kinds regards,
Poel++
Oh, kernel stuff, can't help you here. Sorry. But I do know of a couple of OS sites (that have forums in them) that might give you a better reply than me.

http://www.osdever.net/
http://www.osdev.org/index.html

Biased turkey
December 4th, 2005, 06:53 PM
From my experience: I took a C programming course at the University of Montreal. The instructor ( a Vietnamese guy ) was excellent. Then I purchased the Sams book "Teachyourself C++ in 21 days" ( very good book imho ).
I wish I'd have done it the other way around: Learn C++ and the C.
Learning C is easier if you know C++ first. And who, in the real world, is still programming in C ?

Jengu
December 4th, 2005, 11:38 PM
And who, in the real world, is still programming in C ?

How about Linus Torvalds? (http://www.kernel.org) Or maybe a rogue group of desktop developers...
(http://www.gnome.org)

YourSurrogateGod
December 6th, 2005, 05:32 PM
Hello. I am just starting to learn C, which is going to be my first programming language. Does anyone know of any good tutorials and/or books for C?
One more thing. Learn how to use Makefiles, they are a great. Here (http://www.eng.hawaii.edu/Tutor/Make/) is a tutorial on how to make one.