Hello Glynn and the group,
I am learning C and agree with every word you say below. The
reason C is used so much is that it is close to assembly level but not so
close you must deal with everything you do in assembly.
For many years I wanted to learn C but my work was in management
and not Electrical Engineering as I started out. Never got it done but now
in retirement the chance is here and at this time I am working the
problems at the end of chapter 9 in the book "New C Primer Plus", Waite
Group/Sams, 1993, International Standard Book # 0-672-30319-1.
Yesterday I took an example program written earlier that asks for
any number and the integer power to raise to. But as it stood it would not
do the case when either number was zero or if either number was < 0. It
all went fine until I got to a step where I wanted to convert a number, if
it was < 0 to a positve number. I asked an old (74) friend if he knew what
to do and Dr. Hamilton Marshal said " multiply it by -1". Of course that
was exactly what to do. Here is what I wrote and it works fine:
/* raises numbers to integer powers */
#include <stdio.h>
double power(double a, int b);
int main(void)
{
double x, xpow;
int n;
printf("Enter a number and the positive integer power to which\n"
"the power will be raised. Enter q to quit.\n");
while(scanf("%lf%d", &x, &n) == 2)
{
xpow = power(x,n);
printf("%.3e to the power %d is %.3e\n", x, n, xpow);
}
return 0;
}
double power(double a, int b)
{
double pow = 1.0;
int i;
if ( a == 0 )
return 0;
if ( b == 0 )
return 1;
if ( b < 0)
{
b = b * -1; /* makes b a positive number */
for ( i=1; i <= b; i++)
pow = pow * a;
return 1 / pow;
}
else
{
for( i=1; i <= b; i++)
pow = pow * a;
return pow;
}
}
This is what the book gets you doing. And it teaches you the ANSI
version of C which helps get the function identifiers accurate and makes
the use of pointers more apparent. At this point I see pointers as a way
to transfer more then just a single result from one to another function.
I'm sure there are other uses.
So this is where I am. And a question arises: Is this a Sig where
my level of C programming development should be? Sure looks like You and
others are way ahead of me.
On Fri, 12 Jun 1998, Glynn Clements wrote:
>
> MCENANEY WILLIAM J wrote:
>
> > I'm sorry to trouble you, but I'm doubting whether I can program well in C.
> > If you know of any books that might help me, please suggest them. After
> > I droned on about readable code, I knew that C wasn't my problem. I my
> > poor skill was my problem. Thanks so much.
>
> I can't think of any specific books offhand. However, I'd like to make
> a few points.
>
> Firstly, C is a fairly low-level language. C statements translate to
> machine code in a relatively direct fashion. In order to understand
> many of the things that people do in C, it's necessary to have some
> degree of understanding of low-level concepts, particularly with
> regard to pointers.
>
> People who are taught C on CS courses as if it were Pascal often get
> burned by not understanding concepts such as memory management, e.g.
> returning pointers to (automatic) local variables, or not copying the
> contents of static buffers (e.g. those returned by functions such as
> gethostbyname) before they get overwritten.
>
> Secondly, C can be (and often is) used as a general-purpose language
> for application development. Consequently, most of the things that
> apply to programming generally apply to C.
>
> All in all, being a good C programmer is a mixture of understanding:
>
> a) computers
> b) programming
> c) C itself
>
> c) is probably the least of the three requirements. K&R is only about
> 250 pages (and a large chunk of that is appendices), and it gives good
> (if somewhat brief) coverage of the language.
>
> a) is pretty useful for C programming. You can write programs in C
> without too much understanding of the lower levels, but you'll have
> trouble understanding much of what other people write. Though not
> essential, I think that having learnt assembly language first made it
> much easier for me to learn C.
>
> b) is open ended. You could dedicate your entire life to learning one
> very specific topic, yet still only cover a fraction of it. A good
> knowledge of standard techniques is (IMHO) indispensable. Learning
> lots of different languages also helps.
>
> Unfortunately, books which deal with core theory seem to be getting
> harder to get hold of as computers become more widely used. Instead,
> you get shelves upon shelves of copies of `XXX for dummies', where XXX
> is some software package that will probably be consigned to history
> within 5 years.
>
> --
> Glynn Clements <[EMAIL PROTECTED]>
>
Best wishes
- Karl F. Larsen, 3310 East Street, Las Cruces,NM (505) 524-3303 -