Is "C For Dummies" any good?

M

Mabden

Randy Howard said:
Mabden, please get your attributions correct, I did NOT write
what you are replying to below... and yes, this is an intentional
top-post, since the contents are incorrect below.

Shit happens.
 
M

Malcolm

Joona I Palaste said:
It depends. I have got quite far mostly knowing Java. I know C, but it
hasn't really come into use in either of my jobs so far.
But you still have to know C, even if you don't use it as your main
development language. For instance have you never needed to translate a
routine written in C into Java?
 
K

K. G. Suarez

What are your programs like so far? All I can do is modify code. People
have said that it is good to look at others people's code. So what I am
doing now is: I download some code and then look thought it, when I find
something I don't recognize, I look it up in K&R.

Is this a good way to learn? Back when I tried to learn from K&R, and
even now with "C For Dummies", I have had trouble understanding what the
text is talking about. I usually have no clue what's going on until I
see the code. Should I open up K&R, find some nice big piece of code and
try to figure out what's going on? How have some of you learned? Should
I sign up for a class? I don't want a class where I will have to use a
Windows machine. I like to use my FreeBSD machine for stuff like this.
And I don't care for GUI related stuff. I am perfectly fine with CLI.

Speaking of my FreeBSD machine... I can't post to this newsgroup with
it. I have no idea what the problem is... I can post to some other
newsgroups. Does anyone know what's up?
 
N

newby2c

[K. G. Suarez] wrote ...
What are your programs like so far? All I can do is modify code.

Greetings K.G.,

I'm not sure you were directing your message to me, but I think you were.
Anyway, here is some code I wrote with the knowledge gained so far, from "C
for Dummies". It is a program that converts U.S. dollars into British
pounds. Not bad for a complete newby2c. And I'm only on chapter 9!

-------------- begin code ----------------------
/* currency.c */

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
float us=1.00;
float total;

printf("%50s","Currency Converter\n");
printf("\n");
printf("Enter amount in U.S. currency to convert: ");
scanf("%f",&us);
total=us*0.586550;
printf("\n");
printf("The total amount in British Pounds is %.2f\n",total);

system("pause");

return 0;
}
----------------- end of code -------------------

I hope this helps you some.

Best,
newby2c
 
B

Bernhard Holzmayer

K. G. Suarez said:
Hello everyone.

I am new to programming and my uncle gave me a copy of "C For
Dummies 2nd Edition". I am up to chapter 9 right now. He probably
saw me struggling with "The C Programming Language" by Ritchie and
Kernigahn and felt bad.

Does anyone have experience with this book? I feel that it is
helping me along pretty well. But how much will this book teach
me? What would be the next book to read?

My suggestion:

If you feel good with the book = it pleases you and you like the
style how it is written, then go ahead with it.

Don't expect that you'll be master of the C universe after you have
finished with you reading.

Learning C is (like learning any spoken language) learning
syntactical elements, semantical rules and then develop a living
style.
You may learn syntactical elements and some semantical rules from
such a book. Reading another one might add to your knowledge.

But at some certain point you have to made that decision, that
either you drop this language, or start living with it.

As soon as you make up your mind to make this language part of your
life, you'll start to really "learn C".

You'll stop reading books, you'll start reading code from other
developers, creating code by yourself, getting it criticized by
others, redoing it at a whole or part of it, and sometimes throw it
away after lots of wasted hours and days.

Years later, you might end up as a good programmer,
either because you started with a book like "C For Dummies" -
or because you dropped it and started with any other.

There are three important things:
from any hint anybody gives you, retrieve the good part and keep it.
from the same hint, retrieve the bad part, and ignore it.
go ahead with what you think is the best.

Bernhard
 
E

Emmanuel Delahaye

newby2c wrote on 26/07/04 :
/* currency.c */

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])

Why defining parameters you don't use at all ?
{
float us=1.00;

Why using 'float' instead of 'double' ?
float total;

printf("%50s","Currency Converter\n");
printf("\n");
printf("Enter amount in U.S. currency to convert: ");

(FAQ) The string is not terminated by a '\n'. Depending on the
platform, it may output on stdout or not. To be sure of it, force it:

fflush (stdout);
scanf("%f",&us);

What happens if the user types a wrong entry ? scanf() is a difficult
function, not only for beginners. I suggest a combination of fgets()
and strtod().
total=us*0.586550;

What if the rate changes ?
printf("\n");
printf("The total amount in British Pounds is %.2f\n",total);

system("pause");

Bare in mind that this 'trick' is due to your C implementation.
 
J

Joona I Palaste

Malcolm said:
But you still have to know C, even if you don't use it as your main
development language. For instance have you never needed to translate a
routine written in C into Java?

Yes I have. But only once so far. And it was fairly simple C, with most
of the difficulty being in the algorithm itself.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'It can be easily shown that' means 'I saw a proof of this once (which I didn't
understand) which I can no longer remember'."
- A maths teacher
 
R

Rouben Rostamian

[K. G. Suarez] wrote ...
I'm not sure you were directing your message to me, but I think you were.
Anyway, here is some code I wrote with the knowledge gained so far, from "C
for Dummies". It is a program that converts U.S. dollars into British
pounds. Not bad for a complete newby2c. And I'm only on chapter 9! ....snipped...
printf("Enter amount in U.S. currency to convert: ");

This needs to be followed by
fflush(stdout);

....more snipped...
system("pause");

Did the book tell you that "pause" is avaialble only on certain platforms?
 
M

Malcolm

Joona I Palaste said:
Yes I have. But only once so far. And it was fairly simple C, with most
of the difficulty being in the algorithm itself.
I suppose it depends what sort of programs you write. Stealing snippets of
code is something I do constantly.
 
W

Wayne Rasmussen

Rouben said:
I suggest that you don't read "C For Dummies". It has the potential
to mislead you.

I am basing this statement based on the author's VERY confused
rambling in:

http://www.c-for-dummies.com/lessons/linux/01/index.html

He shows a program that compiles and runs under Windows but
crashes under Linux. He appears to puzzled why this happens.

His problem is that he is trying to modify a string literal.
That's in violation of the C standard.

This is Question 1.32 in comp.lang.c's FAQ.

At least he should be given credit for his honesty.

I like how he blames in on linux.
 
N

newby2c

[snip]
Why defining parameters you don't use at all ?
[snip]
Why using 'float' instead of 'double' ?
[snip]
(FAQ) The string is not terminated by a '\n'. Depending on the
platform, it may output on stdout or not. To be sure of it, force it:

fflush (stdout);
[snip]
What happens if the user types a wrong entry ? scanf() is a difficult
function, not only for beginners. I suggest a combination of fgets()
and strtod().
[snip]
What if the rate changes ?
[snip]
Bare in mind that this 'trick' is due to your C implementation.

Greetings Emmanuel,

I think you may have missed an earlier post of mine in this thread, or maybe
just misunderstood it, so I'll post it again. I am brand new to any type of
programming, and I've only read nine chapters (small ones too) of an
incredibly basic approach to the C language. The only reason I even posted
that code was to show the OP how to put into practical use what was being
taught. He mentioned that he was only able to work and alter pre-made code,
and asked me what I was doing. With that said, I will try to answer your
questions.

#1. This was done by the DevC++ editor after I chose the option to create a
new project (console). Yes, I could have and should have, just used int
main().

#2. Why use 'double'? I wrote this program for myself to determine the cost
of an eBay auction that was in British pounds (this was before eBay provided
that info). I knew I would not be entering anything requiring 'double'.

#3. Sorry, I didn't get that far yet, so I made use of what I knew. I'll be
on the lookout for that though.

#4. I agree 100% with you on this. However, as above, I haven't yet learned
any other way of doing it yet.

#5. I was, and am aware of that, and it frustrates the hell out of me. As a
matter of fact, it does change quite often. What do you suggest?

#6. Yes, I understand that it is not very portable. But again, it was only
for my use (I know, that's no excuse), and it was really fun to go through
the thought process for designing it.

Best,
newby2c
 
N

newby2c

Rouben Rostamian said:
This needs to be followed by
fflush(stdout);

...more snipped...

Did the book tell you that "pause" is avaialble only on certain platforms?

Greetings Rouben,

Please see my reply to Emmanuel.

Thanks.
 
N

newby2c

Bernhard Holzmayer said:
My suggestion:

If you feel good with the book = it pleases you and you like the
style how it is written, then go ahead with it.

[snip]

Greetings Bernhard,

I know you wrote this to the OP and not I, but I just wanted to say that you
gave some great advice, and as a neophyte myself, I intend to follow it.

Best,
newby2c
 
K

Keith Thompson

newby2c said:
#1. This was done by the DevC++ editor after I chose the option to create a
new project (console). Yes, I could have and should have, just used int
main().

Or, better yet, int main(void).
#2. Why use 'double'? I wrote this program for myself to determine the cost
of an eBay auction that was in British pounds (this was before eBay provided
that info). I knew I would not be entering anything requiring 'double'.

Type double typically has a greater range *and* precision than float
(though this isn't guaranteed). If you're dealing with reasonable
amounts of money, the extra range isn't going to matter, but the
precision could. Typical amounts of money (such as 0.10) aren't
exactly representable in binary floating-point. Using double rather
than float can alleviate, but not solve, this problem. See section 14
of the C FAQ, <http://www.eskimo.com/~scs/C-faq/faq.html>.
 
N

newby2c

Keith Thompson said:
Type double typically has a greater range *and* precision than float
(though this isn't guaranteed). If you're dealing with reasonable
amounts of money, the extra range isn't going to matter, but the
precision could. Typical amounts of money (such as 0.10) aren't
exactly representable in binary floating-point. Using double rather
than float can alleviate, but not solve, this problem. See section 14
of the C FAQ, <http://www.eskimo.com/~scs/C-faq/faq.html>.

Thanks for the explanation, Keith.

newby2c
 
E

Emmanuel Delahaye

newby2c wrote on 26/07/04 :
#1. This was done by the DevC++ editor after I chose the option to create a
new project (console). Yes, I could have and should have, just used int
main().

Ok, or int main (void)

that clarifies your intention.
#2. Why use 'double'? I wrote this program for myself to determine the cost
of an eBay auction that was in British pounds (this was before eBay provided
that info). I knew I would not be entering anything requiring 'double'.

double are used for computing because they have a better precision. Any
float will be converted to a double (with a cost in terms of code space
and CPU time) before being processed (computing, function parameter
etc.).

Better to have it as the basic type that double is. float being
generally smaller (hence less accurate) than double, they are used to
store big arrays of values when high precision is less required than
room.

Note that if you inist in using scanf() with the address of a double,
the correct formatter is "%lf". (point #4)
#3. Sorry, I didn't get that far yet, so I made use of what I knew. I'll be
on the lookout for that though.

It is well explained in the FAQ. It's an implementation-dependent issue
that concerns portability. Don't forget that here, on c.l.c, we are
speaking of the C-language, independently from any implementation.
Hence, we try to stay portable.
#4. I agree 100% with you on this. However, as above, I haven't yet learned
any other way of doing it yet.

I still don't understand why book writers do continue to teach scanf()
before gets()... Kinda mystery to me...
#5. I was, and am aware of that, and it frustrates the hell out of me. As a
matter of fact, it does change quite often. What do you suggest?

At minimum, a command line parameter to avoid to recompile the program
each times! Incidently, it will give you the opportunity to learn how
to manage the command line parameters and the

int main (int parameters_count, char ** array_of_strings)

form of main.
#6. Yes, I understand that it is not very portable. But again, it was only
for my use (I know, that's no excuse), and it was really fun to go through
the thought process for designing it.

We are not supposed to post system dependent code in here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,372
Latest member
LucretiaFo

Latest Threads

Top