• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C programming help

Status
Not open for further replies.

Kurupt

New Member
I was wondering if anyone knew of any good C programming books to learn from.

I'm an engineering student and am taking an introductory course on C programming. The instructor told us to get C How to Program Fourth Edition by Deitel and Deitel. The book isn't too great on explaining the concepts and I was wondering if anyone knew of some good books to learn from.

The course covers the simple stuff like if/else, do/while etc., as well as functions, arrays, pointers and classes. If anyone knows of some good books or websites that explain these concepts well could you let me know.

Thanks.
 

crust

Member
I like the book "data structures and algorithms in C" ... it is not as much a tutorial, but provides very good descriptions of algorithms and methods that you are likely to use as an engineer?

As an aside, here is a tip/trick --

Which is preferred, statement A or B and why?

A: if (x == 11) { ... }
B: if (11 == x) { ... }
 

Well Cookin

New Member
'The C Programming Language' by Brian W. Kernighan and Dennis M. Ritchie is the C programmers bible. Known in the trade as the 'Kernighan and Ritchie' or 'K&C' book - many swear by it. It is concise and makes an excellent reference book. Yes you can get books full of tips and tricks and these are good too. But I feel that modern programming language books are too wordy - they take several pages to teach you something that K&C does in a one. It's a matter of personal need and taste I guess.
 

Agent 009

New Member
Deitel's publications

I don't know why you thought Deitel's book isn't so great. Because I ran into a lot of Deitel's publications, C++ included, and they were just great: you could study a course on programming just self-paced! No need for anyone to explained more! Anyway, you don't like it, you don't like it.. If you ever need help in a program or something, just tell me. I'm also an engineering student...
 

StupidDum

New Member
I first learned C in an "IT" way, meaning, declare as many variable as i like, dont bother about byte,long, double... since we have unlimited RAM, and high speed in our PC.
However, after i started programming C for PIC, then i realised the difference of C between engineering and IT. I have to consider carefully before using any BIT of RAM, and write efficient code to reduce the program memory needed...etc
 

Well Cookin

New Member
Very true indeed StupidDum.

There is a world of difference between programming for a resource-rich environment such as a PC and the limited resources of the embedded system. Many considerations need to be included at the design stage such as memory size and its physical location, computational costs, interrupt timing, bus bandwidths, hardware delays and so on... Most (if not all) of these can be conveniently ignored when writing for a PC - which is probably why most PC software is really 'bloatware'. That's not to say that PC software (e.g. Windows) is bad (although sometimes it feels that way!). If resources are abundant then, apart from the obvious gains of being able to add more functionality, you can consider using better programming methodologies (such as OO) and making the software more flexible, maintainable and more platform independent.

There's always a trade-off between efficiency and flexibility.

Yer pays yer money, an' yer makes yer choice...
 

Sherif Welsen

New Member
Try this book:
C Programming using Turbo C++, by Robert Lafore.
Its really good book.
 

fat-tony

Member
In my intro course, we're using C++ For Scientists and Engineers (I think that's what it's called). We haven't actually used any of the C++ structures like vectors, stacks, etc..., and it has been 99% C compatible code. It's been a pretty good little refresher (I used to program in C, and then kinda fell out of habit).

Our class website is at http://www.cs.usask.ca/classes/index.jsp?class=116&section=T1 if you're interested.
 

eemage21

New Member
"SAM's Teach yourself C in 21 Days" - hands down the best book out there. I love their books.
That one covers everything you need to know, and explains it really easy.
 

Agent 009

New Member
Yeah, the SAM's editions are great for fast learning. I had the C++ in 21 days. But maybe you should consider the Deitel's book.. I think they're the best...
 

petesmc

New Member
B: if (11 == x) { ... } is the preferred statement, because it's faster for a compiler to compile as it is in a better format for reverse polish notation (RPN).

Just a guess... :)
 

crust

Member
petesmc said:
B: if (11 == x) { ... } is the preferred statement, because it's faster for a compiler to compile as it is in a better format for reverse polish notation (RPN)
Sorry to hijack the thread ... thats a good guess, but not correct. RPN is reverse polish notation (as petesmc mentioned). I'll give this a few more days and I'll post the reason why.
 

riteet

New Member
which is better?

Crust,

Would a bigger part have to deal with the design of the compiler being used?

Paradigm's tool gave me the exact same assembly for each of the mentioned code snippets:

; if (x == 11)
;
?debug L 9
cmp word ptr [bp-2],11
jne short @[email protected]

; if (11 == x)
;
?debug L 14
cmp word ptr [bp-2],11
jne short @[email protected]

since I can't see the difference in the assembly, I'll either say that it would depend on the compiler. But could it be that one syntax over the other might make it easier/quicker for the parser? That's all I got now I'm frustrated :!:
 

crust

Member
Re: which is better?

riteet said:
But could it be that one syntax over the other might make it easier/quicker for the parser?
That is a very close guess as to why one is better than the other. In fact, the assembly should not be any different b/c the statement is fairly simple and the comparison is commutative.
 

crust

Member
Re: which is better?

riteet said:
But could it be that one syntax over the other might make it easier/quicker for the parser?
That is a very close guess as to why one is better than the other. In fact, the assembly should not be any different b/c the statement is fairly simple and the comparison is commutative.
 

crust

Member
crust said:
Which is preferred, statement A or B and why?

A: if (x == 11) { ... }
B: if (11 == x) { ... }
The latter is preferred ... the reason is that if you make a simple typo for example:

if (x=11) {...}

that is one of the most difficult bugs to catch. The conditional is executed every time in addition to altering the value of x.

On the other hand, take for example:

if (11=x) {...}

If the same typo is made here, the compiler will catch the error and refuse to continue compiling the program because the constant 11 cannot be an lvalue.

There are some compilers (not many ... and you usually have to have the certain options enabled) that can WARN on the first one. But *every* compiler will error out in the second case.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top