Learning C


realyst

Member
Joined
Jan 15, 2006
Messages
206
Location
Halifax, NS, Canada
Website
real-ism.com
Apologies, I wasn't sure if I should tap the knowledgebase here on in General Talk :p

I've been using interpreted languages for a bit and wanted to pick up something more low-level and would allow me to experiment with things like the upcoming demon device.

Any suggestions on reading material or even Windows based compilers?(I have a Linux build on my Laptop, but I wanna play around with both Window and Linux).

Any suggestions that'll get me 'Hello World'ing in C is much appreciated :)
 
realyst said:
Any suggestions that'll get me 'Hello World'ing in C is much appreciated :)
Linux:CODE
#include <stdio.h>

int main()
{
printf("Hello World\n");
return 0;
}



Then, in most distributions you would save the code, run
QUOTE
g++ code.c -o name_of_my_program
thenQUOTE
./name_of_my_program
in a terminal.
If you're looking for more than just Hello World, I'd suggest a book: "Beginning Linux Programming 4th Edition" from Wrox Programmer to Programmer.

http://search.barnesandnoble.com/Beginning...70147627/?itm=1

It is very well written, covers shell scripting and basic C. I would start learning on the Linux side of things simply because it is going to get you closer to standardized C than anything, and code is easy to migrate to pretty much any platform. The above book is what I've been using to re-learn alot of C, and has so far been an invaluable resource for some of my upcoming projects.
Feel free to PM me if you have any specific questions.
Good luck and happy coding. :lol:
 
Last edited by a moderator:
Thanks! Clicking through your links and suggestions now :D

@AireTamStorm:

Yeah I figured I was gonna at least start with Linux(it having a compiler and everything ready to go in the first place, etc...).

I've done some shell programming in korn(the shell they default to where I work). And I know I've only scratched the surface on it(mostly just did screen scrapers and data parsers to make my job easier).


@atomicthumbs
I'll see if they have "The C Programming Language" at the local Chapters bookstore so I can browse it but I do like the fact that it supposedly(according to an Amazon comment) skips or quickly covers the rudimentary stuff like variables and simple loops.


@Firefox

Free anything gets extra points :D I think I've heard of this guy too. I like dead-tree books, but having said that, I gotta adapt :)


Again, thanks all :D
 
It's not very original of me to say this again, but I recommend trying Python first. For most intents and purposes it's fast enough and where it isn't, modules can be written in other faster languages.

As for low level languages, personally I find C++ very inconsistent. C is much cleaner, but it shows it's age. On windows, try the MinGW compiler and Notepad++ for editing. On linux you have gcc and Kate. IDEs come much later.

@Firefox: I didn't know about Beej, thanks.
 
sindbad said:
It's not very original of me to say this again, but I recommend trying Python first. For most intents and purposes it's fast enough and where it isn't, modules can be written in other faster languages.

As for low level languages, personally I find C++ very inconsistent. C is much cleaner, but it shows it's age. On windows, try the MinGW compiler and Notepad++ for editing. On linux you have gcc and Kate. IDEs come much later.

@Firefox: I didn't know about Beej, thanks.

Well for C++ and C, it depends if you are looking for something respectively enhanced or coder friendly.
With good organisation and static arrangements (understand "quite monolithic application"), C is a winner.
 
Last edited by a moderator:
sindbad said:
It's not very original of me to say this again, but I recommend trying Python first. For most intents and purposes it's fast enough and where it isn't, modules can be written in other faster languages.
He specifically says he wants something more low level and you tell him to use Python, a language that people take a lot of pride in calling "very high level"?
 
Last edited by a moderator:
Exophase said:
He specifically says he wants something more low level and you tell him to use Python, a language that people take a lot of pride in calling "very high level"?
Yes. I was under the impression he had only tried shell scripting, which is very limited, and that's why he wanted to try something more low-level. And python is more low-level than shell scripting for the most part.

Trying to save him from a world of pain mostly :D
 
Last edited by a moderator:
sindbad said:
Yes. I was under the impression he had only tried shell scripting, which is very limited, and that's why he wanted to try something more low-level. And python is more low-level than shell scripting for the most part.

Trying to save him from a world of pain mostly :D
Don't take this the wrong way but I'd appreciate it if you could spare us the language evangelism/indoctrination ;p One man's pain is another man's pleasure!
 
Last edited by a moderator:
Exophase said:
Don't take this the wrong way but I'd appreciate it if you could spare us the language evangelism/indoctrination :p One man's pain is another man's pleasure!
Not taking it the wrong way.

I'm so bitter against C++ in particular because I've had a lot of scaling issues (on the human-rereading-code part) with a large project. The only way I could keep C++ manageable was by using Qt. C is no better.

Sorry to derail the tread.
 
Last edited by a moderator:
lol

I appreciate the feedback all the same, sindbad :)

I had considered python, but I already have ksh, perl and php under the belt. I keep hearing wonderful things about Python, but, yeah, I wanna get my hands dirty with something low-level for a change, first. And as much as I've heard it's a pain, I wanna try some memory management stuff(letting the interpreter do it feels like cheating if I don't know exactly what it's managing :p )

As for C++, maybe later. I think if I'm going to go hardcore OO(PHP OO certainly doesn't count), I may as well go Java. But maybe my romp through C will change my mind.
 
atomicthumbs said:
I suggest "The C Programming Language" by Dennis Ritchie and Brian Kernighan.
You just can't go wrong with the classics.

Avoid the stream functions many books preach like fopen and fread, stick with the lower level open, read and write routines. The key to great C is organization and discipline, you are the only thing that enforces those such as always writing black box functions with only a single exit point, never put code in a header, main at the bottom, order functions so you don't rely on prototypes in the file declared, consistent style like curly braces on lines by themselves, Global vars start with Caps, defined values in all upper case etc. You make your own rules and conventions and are the only thing that stand between good solid code and unmaintainable crap. Both may run. Most important of all understand the tao.
 
Last edited by a moderator:
**has original copy of The C Programming Language**
Great read, relatively thin too - really relies on foundation knowledge though... I'd recommend something from the "for dummies" or the "Sam's Teach Yourself" series first though. Both very well written and informative.
~Lineus
 
realyst said:
As for C++, maybe later. I think if I'm going to go hardcore OO(PHP OO certainly doesn't count), I may as well go Java. But maybe my romp through C will change my mind.
If you happen to return to us, bemoaning the lack of happy object-oriented code, let me know if I can be of any assistance. :)
 
Last edited by a moderator:
Well there is a huge difference between C++ and Java that you're forgetting. Java is managed, so the coding style is a lot different. Honestly, the big difference between C and C++ comes down to the coder. Some prefer the structure of C++ and some prefer the looseness of C. Both are very effective unmanaged languages.

IF you do want to go Managed, both Java and C# are good languages to look into, but honestly, on embedded systems id rather stick to unmanaged code. The performance advantage is enough to justify the runtime environment, since it also translates into battery life, which is probably the most crucial, neglected (no matter how stressed) factor on any battery based device. At the end of the day, it just sucks to be tethered.
 
NOTE: personal opinion expressed here don't read if you like java XD

personally as an OO language i HATE java... i haven't had much of a chance to do a lot of OO in c++ (but did a lot in my java class) but since the OO is not so deeply inbeded in the language it is easier IMO since you can choose if you want or don't want to use OO or even mix the two

sadly i think that my database management class in the fall will use both java and c++ (apparently banks like java... but who are they to decide what a good OO language is(money talks))

I must admit the java class did bring me up to speed a little more on how classes are used even in C++
 
Apart from a book on C (I started out with a "for dummies" book) I would also recommend getting something like "Focus on SDL". IMHO it's a lot more fun to learn to program when you can display graphics on the screen and this book will have you do that literally within minutes. Plus: SDL is supported by the GP2X, the Pandora and pretty much every other platform on the planet.

RomanH
 
cb88 said:
personally as an OO language i HATE java... i haven't had much of a chance to do a lot of OO in c++ (but did a lot in my java class) but since the OO is not so deeply inbeded in the language it is easier IMO since you can choose if you want or don't want to use OO or even mix the two
There are indeed much better languages than java to learn OO. Objective C and Ruby come to mind. Further nomination would make Exophase want to slap me.
 
Last edited by a moderator:
Back
Top