Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sh?tpile of errors

6 views
Skip to first unread message

Bill Cunningham

unread,
Aug 2, 2008, 1:45:26 PM8/2/08
to
Would anyone be interested in giving this a quick look. The compiler
gave me so many errors I don't know where to start. This is my first use of
isalpha.

#include <stdio.h>
#include <stdlib.h>
#define ex exit(EXIT_FAILURE)

int main(int argc, char *argv[])
{
if (argc != 4) {
puts("print usage error");
ex;
}
if (isalpha(argv[1]) || isalpha(argv[2])) {
puts("name is 3rd arg");
ex;
}
double x, y;
FILE *fp;
x = strtod(argv[1], NULL);
y = strtod(argv[2], NULL);
if (fp = fopen(argv[3], "a"))
== NULL) {
puts("fopen error");
ex;
}
fprintf(argv[3], "%.2f", x, y);
if (fclose(fp))
== NULL) {
puts("fclose error");
ex;
}
return 0;
}

I dunno sigh..

Bill


Doug Miller

unread,
Aug 2, 2008, 2:02:51 PM8/2/08
to
In article <W21lk.68$EL2.41@trnddc01>, "Bill Cunningham" <nos...@nspam.com> wrote:
> Would anyone be interested in giving this a quick look. The compiler
>gave me so many errors I don't know where to start. This is my first use of
>isalpha.

Perhaps you should consider posting the errors you received...

osmium

unread,
Aug 2, 2008, 2:21:05 PM8/2/08
to
"Bill Cunningham" wrote:

> Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start. This is my first use
> of isalpha.

It is not unusual to see a huge number of errors. Start with the first
error and work downward, that's the way the compiler encountered them.
Focus, focus, focus!

I have marked the first one I found after fixing the usual internet munging.

>
> #include <stdio.h>
> #include <stdlib.h>
> #define ex exit(EXIT_FAILURE)
>
> int main(int argc, char *argv[])
> {
> if (argc != 4) {
> puts("print usage error");
> ex;
> }
> if (isalpha(argv[1]) || isalpha(argv[2])) {

*** extra ')' above

Bill Cunningham

unread,
Aug 2, 2008, 2:26:30 PM8/2/08
to

"osmium" <r124c...@comcast.net> wrote in message
news:6fjmsiF...@mid.individual.net...

> "Bill Cunningham" wrote:
>
>> Would anyone be interested in giving this a quick look. The compiler
>> gave me so many errors I don't know where to start. This is my first use
>> of isalpha.
>
> It is not unusual to see a huge number of errors. Start with the first
> error and work downward, that's the way the compiler encountered them.
> Focus, focus, focus!
>
> I have marked the first one I found after fixing the usual internet
> munging.
>
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #define ex exit(EXIT_FAILURE)
>>
>> int main(int argc, char *argv[])
>> {
>> if (argc != 4) {
>> puts("print usage error");
>> ex;
>> }
>> if (isalpha(argv[1]) || isalpha(argv[2])) {
>
> *** extra ')' above

[snip]

I got that one too. I don't see the extra ) myself.

Bill


Bill Cunningham

unread,
Aug 2, 2008, 3:22:23 PM8/2/08
to

"Doug Miller" <spam...@milmac.com> wrote in message
news:3j1lk.16107$xZ.1...@nlpi070.nbdc.sbc.com...

> Perhaps you should consider posting the errors you received...

I would like to but in dealing with bash I don't know the shell commands
to print to stderr. It's something like 2&1 or such.

Bill


Jens Thoms Toerring

unread,
Aug 2, 2008, 4:34:26 PM8/2/08
to
Bill Cunningham <nos...@nspam.com> wrote:
> Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start. This is my first use of
> isalpha.

> #include <stdio.h>
> #include <stdlib.h>
> #define ex exit(EXIT_FAILURE)

> int main(int argc, char *argv[])
> {
> if (argc != 4) {
> puts("print usage error");
> ex;
> }
> if (isalpha(argv[1]) || isalpha(argv[2])) {

A) There is no prototype for isalpha() in scope, you forgot to
include <ctype.h>
B) isalpha() expects an int (typically a char, cast to int) as
its argument, but you pass it a pointer to a string.

> puts("name is 3rd arg");
> ex;
> }
> double x, y;
> FILE *fp;

At least C89 doesn't allow mixing of code and declarations, all
declarations have to come first.

> x = strtod(argv[1], NULL);
> y = strtod(argv[2], NULL);
> if (fp = fopen(argv[3], "a")) == NULL) {

You're missing '(' directly in front of 'fp'.

> puts("fopen error");
> ex;
> }
> fprintf(argv[3], "%.2f", x, y);

fprintf() expects a FILE* as it's first argument, here you pass
it a pointer to a string. I guess you meant to use 'fp' here.
And you have a format specifier for only a single double, but
then pass fprintf() two of them.

> if (fclose(fp)) == NULL) {

First of all, there's a ')' before '==' that's wrong. And then
fclose() returns an int, not a pointer, with 0 indicating success.

> puts("fclose error");
> ex;
> }
> return 0;
> }

Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de

Malcolm McLean

unread,
Aug 2, 2008, 4:35:46 PM8/2/08
to

"Bill Cunningham" <nos...@nspam.com> wrote in message
news:W21lk.68$EL2.41@trnddc01...

> Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start.
Really you need to start with error one and work down.

\However
1) you need to include ctype.h for the isalpha prototype
2) the function works on a single character, not a string, so you need to
pass
it argv[1][0], presuming that you want to check the first character of
argv[1].


--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Martin Ambuhl

unread,
Aug 2, 2008, 5:01:25 PM8/2/08
to
Bill Cunningham wrote:
> Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start. This is my first use of
> isalpha.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h> /* mha: added */
/* mha: removed silly macro */

int main(int argc, char *argv[])
{
if (argc != 4) {

fputs("print usage error\n", stderr);
exit(EXIT_FAILURE);


}
if (isalpha(argv[1]) || isalpha(argv[2])) {

fputs("name is 3rd arg\n", stderr);
exit(EXIT_FAILURE);


}
double x, y;
FILE *fp;
x = strtod(argv[1], NULL);
y = strtod(argv[2], NULL);

if (!(fp = fopen(argv[3], "a"))) { /* mha: fixed parenthesis
error */
fputs("fopen error\n", stderr);
exit(EXIT_FAILURE);
}
fprintf(fp, "%.2f %.2f\n", x, y); /* mha: fixed multiple errors
in arguments to fprintf.
Since there is no way to be
sure what you are trying to
do, I had to guess. */
if (fclose(fp) == EOF) { /* mha: fixed parenthesis error and
completely bogus comparison to
NULL */
fputs("fclose error\n", stderr);
exit(EXIT_FAILURE);
}
return 0;
}

Robert Gamble

unread,
Aug 2, 2008, 5:32:16 PM8/2/08
to
On Aug 2, 1:45 pm, "Bill Cunningham" <nos...@nspam.com> wrote:
>     Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start. This is my first use of
> isalpha.

[snip]

It looks like you have been working on learning C for about a year now
and don't have much to show for it. You still seem to lack a basic
understanding of the fundamentals and you don't seem to be able to
meaningfully incorporate the answers you have received in this group
into your education. If you have made a sincere effort over the last
year to learn C then my advice is to recognize that programming just
isn't your thing, stop wasting your time and find something you are
good at. If you haven't made a real effort then stop wasting
everyone's time with elementary questions whose answers you can't seem
to benefit from anyway and either make an honest attempt on your own
or find something else to keep you busy.

--
Robert Gamble

Malcolm McLean

unread,
Aug 2, 2008, 5:54:55 PM8/2/08
to
"Robert Gamble" <rgam...@gmail.com> wrote in message

>It looks like you have been working on learning C for about a year now
>and don't have much to show for it.

According to Chris Torek there are some medical issues here.

There can be reasons for learning programming other than to get a job as a
computer programmer. For instance the mental activity may keep the brain
working and help to forestall further deterioration.

Needless to say you are not obliged to engage anyone in message exchange.
Judicious use of killfile if another poster irritates you is the way to go.

Default User

unread,
Aug 2, 2008, 6:05:32 PM8/2/08
to
Robert Gamble wrote:

> On Aug 2, 1:45 pm, "Bill Cunningham" <nos...@nspam.com> wrote:
> >     Would anyone be interested in giving this a quick look. The
> > compiler gave me so many errors I don't know where to start. This
> > is my first use of isalpha.
>
> [snip]
>
> It looks like you have been working on learning C for about a year now
> and don't have much to show for it.

Ha ha! A YEAR? More like eight years.

Brian

Ian Collins

unread,
Aug 2, 2008, 6:23:34 PM8/2/08
to
Bill Cunningham wrote:
> Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start. This is my first use of
> isalpha.
>
Why don't you learn to compile a few lines at a time?

--
Ian Collins.

Bill Cunningham

unread,
Aug 2, 2008, 7:42:14 PM8/2/08
to

"Robert Gamble" <rgam...@gmail.com> wrote in message
news:90d06de5-8b5b-418c...@k13g2000hse.googlegroups.com...

... and you don't seem to be able to


meaningfully incorporate the answers you have received in this group
into your education.

I strongly disagree. I've never use ctype or even talked about for example.

Bill


Bill Cunningham

unread,
Aug 2, 2008, 7:44:56 PM8/2/08
to

"Jens Thoms Toerring" <j...@toerring.de> wrote in message
news:6fjumiF...@mid.uni-berlin.de...

> A) There is no prototype for isalpha() in scope, you forgot to
> include <ctype.h>
> B) isalpha() expects an int (typically a char, cast to int) as
> its argument, but you pass it a pointer to a string.

[snip]

Thanks Jen. I've never used of thought of ctype.h.

Bill


Bill Cunningham

unread,
Aug 2, 2008, 7:46:52 PM8/2/08
to

"Malcolm McLean" <regn...@btinternet.com> wrote in message
news:4KGdnUNkFL2-WAnV...@bt.com...

> \However
> 1) you need to include ctype.h for the isalpha prototype
> 2) the function works on a single character, not a string, so you need to
> pass
> it argv[1][0], presuming that you want to check the first character of
> argv[1].
>

Ok I see thanks. strchar is probably needed too. I guess that means
string.h is needed. I've never got so many errors from a compiler before.

Bill


Bill Cunningham

unread,
Aug 2, 2008, 7:48:20 PM8/2/08
to

"Martin Ambuhl" <mam...@earthlink.net> wrote in message
news:TIGdnRoOIZmyVgnV...@earthlink.com...

Now I see that strchr is going to be needed here. I'm using headers too
I've never used.

Bill


Bill Cunningham

unread,
Aug 2, 2008, 7:50:26 PM8/2/08
to

"Ian Collins" <ian-...@hotmail.com> wrote in message
news:6fk536F...@mid.individual.net...

> Why don't you learn to compile a few lines at a time?
>

How would I learn to do that? I've never received so many errors from a
compiler before. I have surmised on my own strchr is going to be needed.
Others say ctype.h which I've never used. Nothing like debugging with a few
others more experienced ;)

Bill


Bill Cunningham

unread,
Aug 2, 2008, 7:54:51 PM8/2/08
to

"Bill Cunningham" <nos...@nspam.com> wrote in message
news:qh6lk.102$mP.55@trnddc03...

>
> "Robert Gamble" <rgam...@gmail.com> wrote in message
> news:90d06de5-8b5b-418c...@k13g2000hse.googlegroups.com...
>
> ... and you don't seem to be able to
> meaningfully incorporate the answers you have received in this group
> into your education.

I am also writing small utilities now. Debugging with others helps you
see your own errors also. I am seeing ways now that I can improve the code
that I would never have been able to see without the involvement of others.

clc is a good place for group debugging.

Bill


Richard Heathfield

unread,
Aug 2, 2008, 8:00:07 PM8/2/08
to
[Quoting marks fixed]

Bill Cunningham said:

>
> "Robert Gamble" <rgam...@gmail.com> wrote in message
> news:90d06de5-8b5b-418c...@k13g2000hse.googlegroups.com...
>
>> ... and you don't seem to be able to
>> meaningfully incorporate the answers you have received in this group
>> into your education.
>
> I strongly disagree.

Robert is right.

> I've never use ctype or even talked about for example.

You missed his point. You still haven't understood the basics of a printf
call, and yet you've rushed ahead onto ctype functions (which you don't
understand either). This flies in the face of all the advice you've
received - to master each new concept thoroughly before moving on to
another. This is an important aspect of learning, and one that you seem
determined to ignore, despite everyone's pleas.

Until you stop flailing around at random, you will never learn C.

Mark Pappin gave you a great chance to rationalise your learning process
and gain a good teacher at the same time, but you threw that chance away.

In fact, you throw away so many chances and come up with so many creative
misunderstandings that I am convinced you are doing it deliberately. The
way you are behaving cannot be explained by mere incompetence.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Keith Thompson

unread,
Aug 2, 2008, 7:57:39 PM8/2/08
to

Starting with the first error your compiler reports. Ignore all the
other errors until you've fixed the first one. Recompile. Later,
rinse, repeat.

Style point: Drop the "ex" macro. When you want to write
exit(EXIT_FAILURE), just write exit(EXIT_FAILURE); it's *much*
clearer, since you don't force the reader to figure out what "ex"
means. Don't use macros to save typing; that's not what they're for.

And I'll discuss just one of several errors you've made. You write

if (fclose(fp) == NULL) { ...

(Well, almost; I've deleted an extra ')'.) What type does fclose()
return? Why are you comparing its result to NULL?

You know that fclose(fp) is the way to close a file; that's good. But
you should have the documentation in front of you, and understand the
types and meanings of any arguments and of the return type, before you
even type the 'f'. The same applies to any standard function (for
example, your incorrect fprintf call in the previous line).

You obviously guessed that fclose() returns a pointer. You guessed
wrong. That's not necessarily a bad thing, but rather than checking
your guess, you went ahead and wrote the call and posted it here.

And you can't depend on the compiler to catch all your errors for you.
For reasons I won't go into right now, a compiler won't necessarily
flag the error of comparing (fclose(fp) == NULL); you could silently
get code that just does the wrong thing.

Take the extra time to check the documentation. It will save you (and
us!) time and effort in the long run.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Bill Cunningham

unread,
Aug 2, 2008, 8:03:19 PM8/2/08
to

"Richard Heathfield" <r...@see.sig.invalid> wrote in message
news:2rWdnTCk7JV1bgnV...@bt.com...

> Mark Pappin gave you a great chance to rationalise your learning process
> and gain a good teacher at the same time, but you threw that chance away.

Maybe he's right from a point of view. Richard I don't think the
tutorial from Mark as well meant as it was was a good idea. Not for him or
me. I'm suprised we made it to question 4. I sometimes need to be almost fed
by the spoonful on this stuff. Maybe hard learning group debugging and k&r2
is the way for me. Then I will eventually learn C. I really don't think Mark
had the patience needed for one like me. What I need is an "LD" teacher.
Anyway from now on I would only like to ask for debugging advice when
necessary a little learning and for the most part we can go our ways.

Bill


Martien Verbruggen

unread,
Aug 2, 2008, 8:01:22 PM8/2/08
to
On Sat, 2 Aug 2008 11:21:05 -0700,
osmium <r124c...@comcast.net> wrote:
> "Bill Cunningham" wrote:
>
>> Would anyone be interested in giving this a quick look. The compiler
>> gave me so many errors I don't know where to start. This is my first use
>> of isalpha.
>
> It is not unusual to see a huge number of errors. Start with the first
> error and work downward, that's the way the compiler encountered them.

That is good advice.

In the below, I'm only going to correct your other advice, and won't try
to play compiler for Bill. All diagnostics needed to 'fix' this program
are provided by his compiler, assuming he allows it to.

>> int main(int argc, char *argv[])
>> {
>> if (argc != 4) {
>> puts("print usage error");
>> ex;
>> }
>> if (isalpha(argv[1]) || isalpha(argv[2])) {
>
> *** extra ')' above

Not above. Below.

>> puts("name is 3rd arg");
>> ex;
>> }
>> double x, y;
>> FILE *fp;
>> x = strtod(argv[1], NULL);
>> y = strtod(argv[2], NULL);
>> if (fp = fopen(argv[3], "a"))

Here.

>> == NULL) {
>> puts("fopen error");
>> ex;
>> }
>> fprintf(argv[3], "%.2f", x, y);
>> if (fclose(fp))

And here.

Martien
--
|
Martien Verbruggen | +++ Out of Cheese Error +++ Reinstall
| Universe and Reboot +++
|

Bill Cunningham

unread,
Aug 2, 2008, 8:12:49 PM8/2/08
to

"Keith Thompson" <ks...@mib.org> wrote in message
news:lnr697c...@nuthaus.mib.org...

> Take the extra time to check the documentation. It will save you (and
> us!) time and effort in the long run.
>

I confuse the return types quite a bit. I was going from memory. I need
to do just what you said basically on this one. ctype.h is a new one to me.

Bill


Richard Heathfield

unread,
Aug 2, 2008, 8:23:19 PM8/2/08
to
Bill Cunningham said:

>
> "Richard Heathfield" <r...@see.sig.invalid> wrote in message
> news:2rWdnTCk7JV1bgnV...@bt.com...
>> Mark Pappin gave you a great chance to rationalise your learning process
>> and gain a good teacher at the same time, but you threw that chance
>> away.
>
> Maybe he's right from a point of view. Richard I don't think the
> tutorial from Mark as well meant as it was was a good idea.

I don't think he was offering you a tutorial. To use a swimming analogy, he
was offering you a lifeline, but it seems that you don't want to grasp it;
you'd rather thrash about, yelling "help" as loud as you can while at the
same time seeing how far out to sea you can get and how powerful a current
you can find.

> Not for him or me.

Certainly not for him. Nobody has that much spare time.

> I'm suprised we made it to question 4. I sometimes need to be
> almost fed by the spoonful on this stuff.

Spoon-feeding is for babies, not for programmers. There is no mental
activity regularly undertaken by large numbers of people that is quite so
difficult as programming. Even lousy programmers have to be pretty bright,
and those who - maybe through no fault of their own - have major
difficulties with learning new things are going to find programming
impossible, because there is so much to learn *and retain*.

> Maybe hard learning group debugging and k&r2 is the way for me.

I disagree. If you have to rely on others to do your debugging for you,
you're not actually learning *anything*. In any case, you haven't reached
the debugging stage yet. You're still at the "it won't compile" stage, and
you can't even balance parentheses. At your current rate of progress, I
shudder to think how long it will take before you can routinely write
moderate amounts of code without troubling the compiler's diagnostic
subsystem.

> Then I will eventually learn C.

I doubt it. Life is not a story-book. Determination is necessary, but
insufficient on its own. You need other qualities to achieve your goals,
and if you want to learn C one of the other qualities you need is mental
discipline, which you appear to lack in bucketfuls.

> I
> really don't think Mark had the patience needed for one like me. What I
> need is an "LD" teacher.

Then I suggest you find one. But you are unlikely to find one here.

> Anyway from now on I would only like to ask for debugging advice when
> necessary a little learning and for the most part we can go our ways.

If you ignore what you are told, why should anyone bother to tell you
anything?

vipp...@gmail.com

unread,
Aug 2, 2008, 8:48:00 PM8/2/08
to
On Aug 3, 2:44 am, "Bill Cunningham" <nos...@nspam.com> wrote:
> "Jens Thoms Toerring" <j...@toerring.de> wrote in messagenews:6fjumiF...@mid.uni-berlin.de...

>
> > A) There is no prototype for isalpha() in scope, you forgot to
> > include <ctype.h>
> > B) isalpha() expects an int (typically a char, cast to int) as
> > its argument, but you pass it a pointer to a string.
>
> [snip]
>
> Thanks Jen. I've never used of thought of ctype.h.

Speak english?

Bill Cunningham

unread,
Aug 2, 2008, 9:02:53 PM8/2/08
to

"Malcolm McLean" <regn...@btinternet.com> wrote in message
news:4KGdnUNkFL2-WAnV...@bt.com...

> \However


> 1) you need to include ctype.h for the isalpha prototype
> 2) the function works on a single character, not a string, so you need to
> pass
> it argv[1][0], presuming that you want to check the first character of
> argv[1].

You are introducing to me a new concept. One I've been waiting to see in
action and no one has ever said anything about it to me before. The reason
for a char**. So that's how it works. Each argument value of course has two
dimensional elements. If argv[1] is a string saying "hello world" then he is
at argv[1][0] and argv[1][1] right? This might sound simple but I haven't
been introduced to multi-dimensional arrays. But I know that's what you're
speaking of.

Bill


Richard

unread,
Aug 2, 2008, 9:05:01 PM8/2/08
to
Richard Heathfield <r...@see.sig.invalid> writes:

> [Quoting marks fixed]
>
> Bill Cunningham said:
>
>>
>> "Robert Gamble" <rgam...@gmail.com> wrote in message
>> news:90d06de5-8b5b-418c...@k13g2000hse.googlegroups.com...
>>
>>> ... and you don't seem to be able to
>>> meaningfully incorporate the answers you have received in this group
>>> into your education.
>>
>> I strongly disagree.
>
> Robert is right.

As was I months ago and was roundly condemned for being a troll. You can
not teach the kind of mindset which makes a programmer. Bill does not
have it. And he will never have it. For one of two reasons

1) He's just a troll having a good laugh at the regs trying to get some
browny points to balance against their other misdeeds.

or

2) He is simply unable to learn from experience.

I favour 1.

Bill Cunningham

unread,
Aug 2, 2008, 9:19:17 PM8/2/08
to

"Richard" <rgr...@gmail.com> wrote in message
news:g7307u$mc3$1...@registered.motzarella.org...

[snip]

> 1) He's just a troll having a good laugh at the regs trying to get some
> browny points to balance against their other misdeeds.
>

I am unaware of anyone on clc's "misdeeds". I condemn no one here for
anything nor will I "get back" at anyone for doing anything to me because no
one here has.

Bill


Keith Thompson

unread,
Aug 2, 2008, 9:41:28 PM8/2/08
to

And that's a symptom of the problem that's preventing you from
learning to program in C.

You know about the isalpha() function. I don't know where you learned
about it, but that doesn't matter.

If you had looked it up in any decent reference book, you would have
discovered that you need to add "#include <ctype.h>" to any source
file in which you use isalpha(). (A reference book that doesn't tell
you this is, by definition, not a decent one.)

Every standard library function is declared in some standard header.
Every time you use a standard library function, you must have a
#include directive for the header that declares it. Every time.
[Yeah, I know you don't always absolutely have to do this, but you
always should, and I'm simplifying just a wee bit.]

The above applies to all C programmers. The following is specifically
for you, Bill.

Every time you want to use a function from the standard C library,
whether it's fopen, fclose, printf, fprintf, isalpha, or anything
else, LOOK IT UP FIRST. Have the documentation for the function in
front of you, and read and *understand*:
what the function does;
the meanings and types of its arguments;
the meaning and type of its return value;
and the header in which it's declared,
before you even consider typing the first letter of the function's
name.

Don't use a function without knowing where it's declared. Don't use a
function without understanding what it does. Don't compare a
function's return value to NULL until and unless you *know* that it
returns a pointer, and what a NULL result means.

I have to look this stuff up myself. I honestly couldn't tell you
with certainty off the top of my head the order of the parameters for
fwrite(). (I just now checked the man page, and found that I had
mentally reversed the second and third parameters.)

If you can learn that lesson (and *retain* it), you'll have made some
actual progress.

CBFalconer

unread,
Aug 2, 2008, 9:53:11 PM8/2/08
to
Bill Cunningham wrote:
> "Jens Thoms Toerring" <j...@toerring.de> wrote in message
>
>> A) There is no prototype for isalpha() in scope, you forgot to
>> include <ctype.h>
>> B) isalpha() expects an int (typically a char, cast to int) as
>> its argument, but you pass it a pointer to a string.
>
> [snip]
>
> Thanks Jen. I've never used of thought of ctype.h.

If you want to use a function the first thing is to look up its
action and parameters in the C standard. At the same time you will
find a listing of the <include.h> file to #include. Then you can
use the function with some clarity.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


D. Power

unread,
Aug 2, 2008, 11:50:47 PM8/2/08
to
In article <W21lk.68$EL2.41@trnddc01>,
"Bill Cunningham" <nos...@nspam.com> wrote:

> Would anyone be interested in giving this a quick look. The compiler
> gave me so many errors I don't know where to start. This is my first use of
> isalpha.
>

> #include <stdio.h>
> #include <stdlib.h>
> #define ex exit(EXIT_FAILURE)
>

> int main(int argc, char *argv[])
> {
> if (argc != 4) {
> puts("print usage error");
> ex;
> }
> if (isalpha(argv[1]) || isalpha(argv[2])) {

> puts("name is 3rd arg");
> ex;
> }
> double x, y;
> FILE *fp;
> x = strtod(argv[1], NULL);
> y = strtod(argv[2], NULL);
> if (fp = fopen(argv[3], "a"))

> == NULL) {
> puts("fopen error");
> ex;
> }
> fprintf(argv[3], "%.2f", x, y);
> if (fclose(fp))

> == NULL) {
> puts("fclose error");
> ex;
> }
> return 0;
> }
>
> I dunno sigh..
>

> Bill


Try #include'ing the standard header where isalpha is defined; <ctype.h>

--
D. Power
"I hold it to be the inalienable right of anybody to go to hell in his
own way."
-Robert Frost

Edward A. Falk

unread,
Aug 3, 2008, 12:13:58 AM8/3/08
to
Aside: is there a verse in Leviticus that says it's an abomination to
format your code properly? I mean, holy crap.

--
-Ed Falk, fa...@despams.r.us.com
http://thespamdiaries.blogspot.com/

santosh

unread,
Aug 3, 2008, 12:15:08 AM8/3/08
to
Keith Thompson wrote:

<snip>

> I have to look this stuff up myself. I honestly couldn't tell you
> with certainty off the top of my head the order of the parameters for
> fwrite(). (I just now checked the man page, and found that I had
> mentally reversed the second and third parameters.)

No surprise there. The order of the second and third parameters to
fread/fwrite *are* unintuitive. That's illustrated by the fact that the
order of these parameters in the prototype and the English description
that follows run in opposite directions.

Chris M. Thomasson

unread,
Aug 3, 2008, 1:07:34 AM8/3/08
to
"Edward A. Falk" <fa...@green.rahul.net> wrote in message
news:g73ba6$nrf$2...@blue.rahul.net...

> Aside: is there a verse in Leviticus that says it's an abomination to
> format your code properly? I mean, holy crap.

Holy Drugs!

http://groups.google.com/group/comp.lang.c/msg/7d3e77e39648006b

http://groups.google.com/group/comp.lang.c/msg/e3f738eb220bbbf1

clonazepam RULES!


:^O

Chris M. Thomasson

unread,
Aug 3, 2008, 1:12:03 AM8/3/08
to

"Chris M. Thomasson" <n...@spam.invalid> wrote in message
news:W_alk.6122$LF2....@newsfe09.iad...

I still think he programs for Microsoft!:

http://groups.google.com/group/comp.lang.c/msg/0815601591d605fd


Okay... Let the cat out of the bag Bill! Your are Gates Right?


Gates has a house right on the north shore of Lake Tahoe, I live in South
Lake Tahoe. Can I visit you?

LOL!


Barry Schwarz

unread,
Aug 3, 2008, 1:16:43 AM8/3/08
to
On Sat, 02 Aug 2008 17:45:26 GMT, "Bill Cunningham" <nos...@nspam.com>
wrote:

> Would anyone be interested in giving this a quick look. The compiler
>gave me so many errors I don't know where to start. This is my first use of
>isalpha.
>
>#include <stdio.h>
>#include <stdlib.h>
>#define ex exit(EXIT_FAILURE)
>
>int main(int argc, char *argv[])
>{
> if (argc != 4) {
> puts("print usage error");
> ex;

After dozens of messages regarding indenting, you still produce
abominations like this. You managed to hit the space bar four times
for the if statement. Is counting to four twice that difficult for
the puts statement.

> }
> if (isalpha(argv[1]) || isalpha(argv[2])) {

Others have told you how to start fixing this.

> puts("name is 3rd arg");
> ex;
> }
> double x, y;

How many times have you been told to put you declarations at the start
of a block?

> FILE *fp;
> x = strtod(argv[1], NULL);
> y = strtod(argv[2], NULL);
> if (fp = fopen(argv[3], "a"))
> == NULL) {
> puts("fopen error");
> ex;
> }
> fprintf(argv[3], "%.2f", x, y);

What is the required type of the first argument to fprintf? What is
the type of this argument in the above statement?

How many format specifications are there in your format string? How
many arguments follow the format string? Should there be a relation
between these two numbers? Does your statement satisfy this relation?

> if (fclose(fp))
> == NULL) {
> puts("fclose error");
> ex;
> }
> return 0;
>}
>
>I dunno sigh..

Two possibilities:

This is very true and YOU are wasting our time.

You are having more fun than we can imagine jerking us around and
WE are wasting our time.

--
Remove del for email

Barry Schwarz

unread,
Aug 3, 2008, 1:16:43 AM8/3/08
to
On Sat, 2 Aug 2008 11:21:05 -0700, "osmium" <r124c...@comcast.net>
wrote:

>"Bill Cunningham" wrote:
>
>> Would anyone be interested in giving this a quick look. The compiler
>> gave me so many errors I don't know where to start. This is my first use
>> of isalpha.
>

>It is not unusual to see a huge number of errors. Start with the first
>error and work downward, that's the way the compiler encountered them.

>Focus, focus, focus!
>
>I have marked the first one I found after fixing the usual internet munging.


>
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #define ex exit(EXIT_FAILURE)
>>
>> int main(int argc, char *argv[])
>> {
>> if (argc != 4) {
>> puts("print usage error");
>> ex;
>> }

>> if (isalpha(argv[1]) || isalpha(argv[2])) {
>

>*** extra ')' above

Would you care to count again?

santosh

unread,
Aug 3, 2008, 1:26:53 AM8/3/08
to
Barry Schwarz wrote:
> On Sat, 02 Aug 2008 17:45:26 GMT, "Bill Cunningham" <nos...@nspam.com>
> wrote:

<snip>

>>I dunno sigh..
>
> Two possibilities:

Not anymore. As Richard Heathfield noted, Cunningham's errors seem too
contrived and creative to be accidental or as a result of mental
deficiency.

I'm putting my money on one of the group's resident trolls as being
behind this "Bill Cunningham" persona. Not even someone on "clozepam"
(or whatever that was called) can mess-up indentation like he's done
here, after being told of countless solutions, on innumerable
occasions. He's a troll all right.

> This is very true and YOU are wasting our time.
>
> You are having more fun than we can imagine jerking us around and
> WE are wasting our time.

Indeed. At least I won't waste mine anymore with "Bill".

Ian Collins

unread,
Aug 3, 2008, 1:26:56 AM8/3/08
to
Barry Schwarz wrote:
>
> Two possibilities:
>
> This is very true and YOU are wasting our time.
>
> You are having more fun than we can imagine jerking us around and
> WE are wasting our time.
>
My money's on number 2.

--
Ian Collins.

santosh

unread,
Aug 3, 2008, 1:35:21 AM8/3/08
to
Ian Collins wrote:

BTW, just remembered an Enid Blyton story from my younger days where a
character posing himself as "Bill Cunningham" later turns out to be a
fake and actually called "Bill Smugs". Sorry forgot the actual name of
the book.

The troll (whichever is behind "Bill") hasn't chosen this nick without
some thought I see.

Default User

unread,
Aug 3, 2008, 2:36:30 AM8/3/08
to
santosh wrote:

> Barry Schwarz wrote:
> > On Sat, 02 Aug 2008 17:45:26 GMT, "Bill Cunningham"
> > <nos...@nspam.com> wrote:
>
> <snip>
>
> > > I dunno sigh..
> >
> > Two possibilities:
>
> Not anymore. As Richard Heathfield noted, Cunningham's errors seem too
> contrived and creative to be accidental or as a result of mental
> deficiency.
>
> I'm putting my money on one of the group's resident trolls as being
> behind this "Bill Cunningham" persona.

This has been going on for many years. I was just reading a thread via
Google Groups from 2003 that sounds eerily like the current ones. Bill
posting weird stuff, not listening to advice, speculation on whether
he's a troll.

I think it's irrelevant as to whether he's a troll or not. If he's made
no more progress in the many years he's been studying C than he has, he
never will. Whether that's by his problems or a lie from trolling
doesn't matter.

People are wasting time.


Brian


William Pursell

unread,
Aug 3, 2008, 3:21:52 AM8/3/08
to
On 2 Aug, 20:22, "Bill Cunningham" <nos...@nspam.com> wrote:
>
>     I would like to but in dealing with bash I don't know the shell commands
> to print to stderr. It's something like 2&1 or such.

Assuming gcc & bash, try:
$ gcc foo.c 2>&1 | less

(Recommended options such as -Wall suppressed for clarity.)

Malcolm McLean

unread,
Aug 3, 2008, 1:44:16 PM8/3/08
to

"Bill Cunningham" <nos...@nspam.com> wrote in message
> You are introducing to me a new concept. One I've been waiting to see
> in action and no one has ever said anything about it to me before. The
> reason for a char**. So that's how it works. Each argument value of course
> has two dimensional elements. If argv[1] is a string saying "hello world"
> then he is at argv[1][0] and argv[1][1] right? This might sound simple but
> I haven't been introduced to multi-dimensional arrays. But I know that's
> what you're speaking of.
>
You've got it almost exactly.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Serve Lau

unread,
Aug 3, 2008, 2:47:31 PM8/3/08
to

"Bill Cunningham" <nos...@nspam.com> schreef in bericht
news:ft6lk.107$mP.68@trnddc03...
> I am also writing small utilities now. Debugging with others helps you
> see your own errors also. I am seeing ways now that I can improve the code
> that I would never have been able to see without the involvement of
> others.
>
> clc is a good place for group debugging.

sounds kinky

Keith Thompson

unread,
Aug 3, 2008, 2:47:57 PM8/3/08
to
"Malcolm McLean" <regn...@btinternet.com> writes:
> "Bill Cunningham" <nos...@nspam.com> wrote in message
>> You are introducing to me a new concept. One I've been waiting to
>> see in action and no one has ever said anything about it to me
>> before. The reason for a char**. So that's how it works. Each
>> argument value of course has two dimensional elements. If argv[1] is
>> a string saying "hello world" then he is at argv[1][0] and
>> argv[1][1] right? This might sound simple but I haven't been
>> introduced to multi-dimensional arrays. But I know that's what
>> you're speaking of.
>>
> You've got it almost exactly.

Section 6 of the comp.lang.c FAQ will explain the "almost".

In particular, strictly speaking, the use of argv doesn't involve
multidimensional arrays; rather, it involves a pointer to the first
element of an array of pointers to strings (where a "pointer to
string" is a pointer to the first element of an array of char
containing a string).

The relationship between arrays and pointers in C has been a stumbling
block for many, probably most, C programmers at one time or another.

Bill, I suggest you *don't* try to understand this stuff just yet.
At least for now, just remember that:

argv can be declared either as int **argv or as int *argv[].
Both mean the same thing; don't worry about the reasons for that.

argv[i], for an integer value i, is a pointer to a string. You
can use it like this:
printf("argv[i] = %s\n", argv[i]);
or, if you can handle a slightly more sophisticated use of printf:
printf("argv[%d] = %s\n", i, argv[i]);

argv[i][j], for integer values i and j, is a char object. (Not
a pointer, an object.) You can use it like this:
printf("argv[i][j] = '%c'\n", argv[i][j]);
or
printf("argv[%d][%d] = '%c'\n", i, j, argv[i][j]);

The syntax ``argv[i][j]'' suggests that argv is a 2-dimensional
array. It really isn't, but you probably won't go *too* far wrong
if you pretend that it is.

This program might help you understand this:

#include <stdio.h>
int main(int argc, char **argv)
{
int i, j;
for (i = 0; i < argc; i ++) {
printf("argv[%d] = \"%s\"\n", i, argv[i]);
for (j = 0; argv[i][j] != '\0'; j ++) {
printf(" argv[%d][%d] = '%c'\n", i, j, argv[i][j]);
}
printf("\n");
}
return 0;
}

Compile it and run it with no arguments, and with one or two fairly
short arguments. Try to understand why I used double quotes in some
one case and single quotes in another.

Bill Cunningham

unread,
Aug 3, 2008, 3:11:37 PM8/3/08
to

"santosh" <santo...@gmail.com> wrote in message
news:g73g2t$ek5$1...@registered.motzarella.org...

> BTW, just remembered an Enid Blyton story from my younger days where a
> character posing himself as "Bill Cunningham" later turns out to be a
> fake and actually called "Bill Smugs". Sorry forgot the actual name of
> the book.
>
> The troll (whichever is behind "Bill") hasn't chosen this nick without
> some thought I see.

Just to point out there's an great many person's around here that use
names I don't think (and I know) aren't real. I do use my birth name except
that it happens to be Wm. with the nick "Bill" and I am not a radio talk
show host.

Bill


Anand Hariharan

unread,
Aug 3, 2008, 3:15:45 PM8/3/08
to
On Sun, 03 Aug 2008 11:47:57 -0700, Keith Thompson wrote:

> argv can be declared either as int **argv or as int *argv[].

Clearly, you meant to say " ... as char **argv or as char *argv[]."

- Anand

Bill Cunningham

unread,
Aug 3, 2008, 3:37:09 PM8/3/08
to

"Barry Schwarz" <schw...@dqel.com> wrote in message
news:mkea94tf8tjrb5v8s...@4ax.com...

[snip]

> After dozens of messages regarding indenting, you still produce
> abominations like this. You managed to hit the space bar four times
> for the if statement. Is counting to four twice that difficult for
> the puts statement.

[snip]

This indenting is the result of indent -kr. It is not my indenting.

Bill


Bill Cunningham

unread,
Aug 3, 2008, 3:44:05 PM8/3/08
to

"Bill Cunningham" <nos...@nspam.com> wrote in message
news:FNnlk.145$xv.103@trnddc02...

> This indenting is the result of indent -kr. It is not my indenting.
>
I was only following advice. But one's advice is another's vice.

Bill


Serve Lau

unread,
Aug 3, 2008, 3:48:05 PM8/3/08
to

"Chris M. Thomasson" <n...@spam.invalid> schreef in bericht
news:73blk.6124$LF2....@newsfe09.iad...

Once he gets to the point he can compile any amount of code he will compile
linux and sell it as the next windows


Keith Thompson

unread,
Aug 3, 2008, 4:52:19 PM8/3/08
to

Yes. (*blush*)

Keith Thompson

unread,
Aug 3, 2008, 4:54:40 PM8/3/08
to

The indent program works best with syntactically correct sources. If
you have syntax errors, such as the mismatched parentheses in the code
you posted, it will produce confusing results.

Bill Cunningham

unread,
Aug 4, 2008, 1:17:42 PM8/4/08
to

"William Pursell" <bill.p...@gmail.com> wrote in message
news:d32ed3d0-4e12-4b31...@79g2000hsk.googlegroups.com...

Assuming gcc & bash, try:
$ gcc foo.c 2>&1 | less

(Recommended options such as -Wall suppressed for clarity.)

Ok that works. Here is my compiler's errors. I have rewritten everything
and since this is non-production code I am using the ex macro to represent
exit(EXIT_FAILURE).

gcc: 2: No such file or directory
p.c: In function `main':
p.c:11: error: syntax error before '{' token
p.c: At top level:
p.c:17: error: conflicting types for 'x'
p.c:16: error: previous declaration of 'x' was here
p.c:17: error: `argv' undeclared here (not in a function)
p.c:17: error: initializer element is not constant
p.c:17: warning: data definition has no type or storage class
p.c:18: error: conflicting types for 'y'
p.c:16: error: previous declaration of 'y' was here
p.c:18: error: initializer element is not constant
p.c:18: warning: data definition has no type or storage class
p.c:19: error: syntax error before "if"
p.c:22: error: syntax error before string constant
p.c:22: error: conflicting types for 'fprintf'
p.c:22: note: a parameter list with an ellipsis can't match an empty
parameter name list declaration
p.c:22: error: conflicting types for 'fprintf'
p.c:22: note: a parameter list with an ellipsis can't match an empty
parameter name list declaration
p.c:22: warning: data definition has no type or storage class

Bill


Bill Cunningham

unread,
Aug 4, 2008, 1:26:25 PM8/4/08
to

"William Pursell" <bill.p...@gmail.com> wrote in message
news:d32ed3d0-4e12-4b31...@79g2000hsk.googlegroups.com...

Assuming gcc & bash, try:


$ gcc foo.c 2>&1 | less

Here's a reposting of the source.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define ex exit(EXIT_FAILURE)

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


if (argc!=4) {
puts("print usage error");
ex;
}

if (isalpha(argv[1]) || isalpha(argv[2]) {
puts("print non alpha allowed");
ex;
}
FILE *fp;
double x,y;
x=strtod(argv[1],NULL);
y=strtod(argv[2],NULL);
if (fp=fopen(argv[3],"a"))==EOF) {
puts("fopen error");
}
fprintf(fp,"%.2f",x,y);
if (fclose(fp))==EOF) {
puts("fclose error");
}
return 0;
}

Bill


Richard

unread,
Aug 4, 2008, 1:26:49 PM8/4/08
to
"Bill Cunningham" <nos...@nspam.com> writes:

> "William Pursell" <bill.p...@gmail.com> wrote in message
> news:d32ed3d0-4e12-4b31...@79g2000hsk.googlegroups.com...
>
> Assuming gcc & bash, try:
> $ gcc foo.c 2>&1 | less
>
> (Recommended options such as -Wall suppressed for clarity.)
>
> Ok that works. Here is my compiler's errors. I have rewritten everything
> and since this is non-production code I am using the ex macro to represent
> exit(EXIT_FAILURE).

Non production code!

LOL! Stop! You're cracking me up!

Oh, and why are you posting the rubbish below?

>
> gcc: 2: No such file or directory
> p.c: In function `main':
> p.c:11: error: syntax error before '{' token
> p.c: At top level:
> p.c:17: error: conflicting types for 'x'
> p.c:16: error: previous declaration of 'x' was here
> p.c:17: error: `argv' undeclared here (not in a function)
> p.c:17: error: initializer element is not constant
> p.c:17: warning: data definition has no type or storage class
> p.c:18: error: conflicting types for 'y'
> p.c:16: error: previous declaration of 'y' was here
> p.c:18: error: initializer element is not constant
> p.c:18: warning: data definition has no type or storage class
> p.c:19: error: syntax error before "if"
> p.c:22: error: syntax error before string constant
> p.c:22: error: conflicting types for 'fprintf'
> p.c:22: note: a parameter list with an ellipsis can't match an empty
> parameter name list declaration
> p.c:22: error: conflicting types for 'fprintf'
> p.c:22: note: a parameter list with an ellipsis can't match an empty
> parameter name list declaration
> p.c:22: warning: data definition has no type or storage class
>
> Bill
>
>

--

Richard

unread,
Aug 4, 2008, 1:31:26 PM8/4/08
to
"Bill Cunningham" <nos...@nspam.com> writes:

I needed a good laugh so I complied the rubbish above. It took 10
seconds to get it to compile with only warnings.

You need to improve your trolling - pretending that you dont know how to
bracket code is simply over the top.

,----


| #include <stdio.h>
| #include <stdlib.h>
| #include <ctype.h>
| #define ex exit(EXIT_FAILURE)
|
| int main (int argc, char *argv[]) {
| if (argc!=4) {
| puts("print usage error");
| ex;
| }

| if (isalpha(argv[1]) || isalpha(argv[2])) {


| puts("print non alpha allowed");
| ex;
| }
| FILE *fp;
| double x,y;
| x=strtod(argv[1],NULL);
| y=strtod(argv[2],NULL);

| if ((fp=fopen(argv[3],"a"))==EOF) {


| puts("fopen error");
| }
| fprintf(fp,"%.2f",x,y);

| if (fclose(fp)==EOF) {


| puts("fclose error");
| }
| return 0;
| }

`----

So come on Bill, you can do better than that!

Bill Cunningham

unread,
Aug 4, 2008, 1:33:38 PM8/4/08
to

"Keith Thompson" <ks...@mib.org> wrote in message
news:lnwsixb...@nuthaus.mib.org...

> Yes. (*blush*)
>
You left me kinda scratching my head there on that one Keith. I'd never
seen int *argv[] before. But what do I know.

Bill


Bill Cunningham

unread,
Aug 4, 2008, 1:36:37 PM8/4/08
to

"Richard" <rgr...@gmail.com> wrote in message
news:g77e50$52s$1...@registered.motzarella.org...

Non production code!


Yes that's right Richard. Non production meant to be used only by me or I
would use exit(EXIT_FAILURE) everytime it is to be used and not the #define
ex macro.

Bill


Bill Cunningham

unread,
Aug 4, 2008, 1:42:20 PM8/4/08
to

"Richard" <rgr...@gmail.com> wrote in message
news:g77ede$52s$2...@registered.motzarella.org...

You need to improve your trolling - pretending that you dont know how to

[snip]

F?ck off.


santosh

unread,
Aug 4, 2008, 1:51:56 PM8/4/08
to
Richard wrote:
> "Bill Cunningham" <nos...@nspam.com> writes:

>> Here's a reposting of the source.
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <ctype.h>
>> #define ex exit(EXIT_FAILURE)
>>
>> int main (int argc, char *argv[]) {
>> if (argc!=4) {
>> puts("print usage error");
>> ex;
>> }
>> if (isalpha(argv[1]) || isalpha(argv[2]) {
>> puts("print non alpha allowed");
>> ex;
>> }
>> FILE *fp;
>> double x,y;
>> x=strtod(argv[1],NULL);
>> y=strtod(argv[2],NULL);
>> if (fp=fopen(argv[3],"a"))==EOF) {
>> puts("fopen error");
>> }
>> fprintf(fp,"%.2f",x,y);
>> if (fclose(fp))==EOF) {
>> puts("fclose error");
>> }
>> return 0;
>> }
>

> I needed a good laugh so I complied the rubbish above. It took 10
> seconds to get it to compile with only warnings.

<snip>

Why republish horribly broken code when you aren't going to attempt to
correct it?

That it compiles is beside the point.

Anand Hariharan

unread,
Aug 4, 2008, 1:56:45 PM8/4/08
to
On Aug 4, 12:33 pm, "Bill Cunningham" <nos...@nspam.com> wrote:
> "Keith Thompson" <ks...@mib.org> wrote in message
>
> news:lnwsixb...@nuthaus.mib.org...
>
> > Yes.  (*blush*)
>
>     You left me kinda scratching my head there on that one Keith. I'd never
> seen int *argv[] before.


There was sufficient context around that particular statement to
suggest that it was just a slip by Keith Thompson.

This was before the statement:

<quote>


In particular, strictly speaking, the use of argv doesn't involve
multidimensional arrays; rather, it involves a pointer to the first
element of an array of pointers to strings (where a "pointer to
string" is a pointer to the first element of an array of char
containing a string).

</quote>

And this after the statement:

<quote>


argv[i], for an integer value i, is a pointer to a string.

</quote>


> But what do I know.
>

Am sure you are following the posts (cf. else-thread by Barry Schwarz,
Santosh, Ian Collins et al.) that have been betting on what exactly
you are doing here?

- Anand

Bill Cunningham

unread,
Aug 4, 2008, 2:09:12 PM8/4/08
to

"santosh" <santo...@gmail.com> wrote in message
news:g77fjv$97o$1...@registered.motzarella.org...

> Why republish horribly broken code when you aren't going to attempt to
> correct it?
>
> That it compiles is beside the point.

This has been re-written Santosh. Or as you say there would have been no
reason to reprint it. I am seeing a lot of notes and warnings from the
compiler too on this one. I was republishing new code for William to look at
as there was a request for compile warnings and the like.

Bill


Richard

unread,
Aug 4, 2008, 2:18:25 PM8/4/08
to
santosh <santo...@gmail.com> writes:

Don't be such a moron all your life Santosh. It compiling is the first
step to get Bill to fix his own bugs. So no, compiling it is NOT beside
the point.

Bill Cunningham

unread,
Aug 4, 2008, 2:23:25 PM8/4/08
to
Santosh or anyone,

isalpha takes as its parameter an int. If it is testing to see if something
is a char it doesn't make sense to me to take an int. What am I not seeing?

http://www.cppreference.com/stdstring/isalpha.html

This is a pretty good reference page. char **argv is the parameter I am
passing to main. isalpha is not going to take this. It wants an int. Am I
going to have to use atoi in here somewhere just to test if something is a
char or not?

Bill


Keith Thompson

unread,
Aug 4, 2008, 2:28:16 PM8/4/08
to

In code meant to be used only by you, you can do anything you like.

If you want to post it here and expect to get help, I suggest that you
drop the "ex" macro and write "exit(EXIT_FILAURE)", so that it's
easier for us to read your code and offer advice.

Keith Thompson

unread,
Aug 4, 2008, 2:31:25 PM8/4/08
to

"int *argv[]" was a mistake on my part. Please ignore it.

What I meant was "char *argv[]".

To restore some context and correct my own error:

argv can be declared either as char **argv or as char *argv[].

santosh

unread,
Aug 4, 2008, 2:32:20 PM8/4/08
to
Bill Cunningham wrote:

>
> "santosh" <santo...@gmail.com> wrote in message
> news:g77fjv$97o$1...@registered.motzarella.org...
>
>> Why republish horribly broken code when you aren't going to attempt
>> to correct it?
>>
>> That it compiles is beside the point.
>

> This has been re-written Santosh. [ ... ]

My question was at Richard.

santosh

unread,
Aug 4, 2008, 2:35:05 PM8/4/08
to
Bill Cunningham wrote:

> Santosh or anyone,
>
> isalpha takes as its parameter an int. If it is testing to see if
> something is a char it doesn't make sense to me to take an int. What
> am I not seeing?

This question has been debated to death here. Just search the archives.

> http://www.cppreference.com/stdstring/isalpha.html
>
> This is a pretty good reference page. char **argv is the parameter I
> am passing to main. isalpha is not going to take this.

Right.

> It wants an
> int. Am I going to have to use atoi in here somewhere just to test if
> something is a char or not?

No. What is the type of argv[n][n]? Will that be compatible with the
type that isalpha takes?

Keith Thompson

unread,
Aug 4, 2008, 2:36:06 PM8/4/08
to
"Bill Cunningham" <nos...@nspam.com> writes:
> "William Pursell" <bill.p...@gmail.com> wrote in message
> news:d32ed3d0-4e12-4b31...@79g2000hsk.googlegroups.com...
>
> Assuming gcc & bash, try:
> $ gcc foo.c 2>&1 | less

Bill, if you can't get OE Quotefix to work for you, then please pay
attention when you post a followup. If the article to which you're
replying was posted through Google Groups, please do *something* to
indicate the division between the quoted material and your new text.

> Here's a reposting of the source.
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <ctype.h>
> #define ex exit(EXIT_FAILURE)
>
> int main (int argc, char *argv[]) {
> if (argc!=4) {
> puts("print usage error");
> ex;
> }
> if (isalpha(argv[1]) || isalpha(argv[2]) {
> puts("print non alpha allowed");
> ex;
> }
> FILE *fp;
> double x,y;
> x=strtod(argv[1],NULL);
> y=strtod(argv[2],NULL);
> if (fp=fopen(argv[3],"a"))==EOF) {
> puts("fopen error");
> }
> fprintf(fp,"%.2f",x,y);
> if (fclose(fp))==EOF) {
> puts("fclose error");
> }
> return 0;
> }

This still has syntax errors. Look at the line with the isalpha
calls. Count the parentheses.

Here's your next assignment. Do not post code that produces an error
message containing the phrase "syntax error" or "parse error". In
most cases, that will be the very first error reported by the
compiler. Fix that error and recompile. Repeat until you have no
syntax errors. *Then* you can post your code and ask for further
help.

Bill Cunningham

unread,
Aug 4, 2008, 2:36:52 PM8/4/08
to

"santosh" <santo...@gmail.com> wrote in message
news:g77hvk$fpe$1...@registered.motzarella.org...

>> This has been re-written Santosh. [ ... ]
>
> My question was at Richard.

My mistake.

Bill


Richard

unread,
Aug 4, 2008, 2:40:19 PM8/4/08
to
santosh <santo...@gmail.com> writes:

> Bill Cunningham wrote:
>
>> Santosh or anyone,
>>
>> isalpha takes as its parameter an int. If it is testing to see if
>> something is a char it doesn't make sense to me to take an int. What
>> am I not seeing?
>
> This question has been debated to death here. Just search the
> archives.

So has every other question asked here. If you are not willing to
explain, why are you here? Will you refer posters to other posts about
casting the return of malloc, the return type of main etc? I doubt it.

>
>> http://www.cppreference.com/stdstring/isalpha.html
>>
>> This is a pretty good reference page. char **argv is the parameter I
>> am passing to main. isalpha is not going to take this.
>
> Right.
>
>> It wants an
>> int. Am I going to have to use atoi in here somewhere just to test if
>> something is a char or not?
>
> No. What is the type of argv[n][n]? Will that be compatible with the
> type that isalpha takes?
>

You are wrong. He might well have to use it if the characters are there
as part of a command line integer parameter. He needs to convert the
character sequence to that integer.

--

Bill Cunningham

unread,
Aug 4, 2008, 2:41:47 PM8/4/08
to

"santosh" <santo...@gmail.com> wrote in message
news:g77i4s$ahg$1...@registered.motzarella.org...

> No. What is the type of argv[n][n]? Will that be compatible with the
> type that isalpha takes?

Oh I see. I've never used argv[][]'s before. I see so much clearly now.
Thank you Thank you. I am going to try this code again.

Bill


santosh

unread,
Aug 4, 2008, 2:44:03 PM8/4/08
to
Richard wrote:
> santosh <santo...@gmail.com> writes:

<snip>

>> Why republish horribly broken code when you aren't going to attempt
>> to correct it?
>>
>> That it compiles is beside the point.
>>
>
> Don't be such a moron all your life Santosh. It compiling is the first
> step to get Bill to fix his own bugs.

No. Understanding C is the first step.

A typical C compiler will gladly accept highly bastardised C and will
attempt to generate an executable. Fixing errors reported by a compiler
*after* having learnt the language is one thing, but depending on
compiler diagnostics to learn the rules and semantics of C is not very
bright, IMO.

> So no, compiling it is NOT beside the point.

Unless invoked in conforming mode an implementation is allowed to
silently accept anything and produce an executable. Even under
conforming mode, only diagnostics are guaranteed. Undefined behaviour
that is not a constraint violation might still be silently accepted and
typically you do *not* want that.

It's better to learn the language first and then use the compiler,
rather than depending on it to learn the language.

Bill should re-open K&R and start with the first page. I understand that
he has not progressed beyond the first few pages after several years,
but he really has no other alternative. Merely messing around with
programs written with guesswork and compiled with luck isn't going to
get him anywhere.

santosh

unread,
Aug 4, 2008, 3:00:02 PM8/4/08
to
Richard wrote:
> santosh <santo...@gmail.com> writes:
>> Bill Cunningham wrote:

>>> char **argv is the parameter I am passing to main. isalpha is not

>>> going to take this. It wants an int. Am I going to have to use atoi


>>> in here somewhere just to test if something is a char or not?
>>
>> No. What is the type of argv[n][n]? Will that be compatible with the
>> type that isalpha takes?
>
> You are wrong. He might well have to use it if the characters are
> there as part of a command line integer parameter. He needs to convert
> the character sequence to that integer.

Don't you find it tiresome to disagree just for the sake of it?

My response was directed at the specific complaint by Bill that
*isalpha* won't like argv as an argument. Clearly he wants to run
through the strings to check whether any of them contain alphabetic
characters (which would be error).

So what you say above makes no sense at all.

Richard

unread,
Aug 4, 2008, 3:04:15 PM8/4/08
to
santosh <santo...@gmail.com> writes:

> Richard wrote:
>> santosh <santo...@gmail.com> writes:
>
> <snip>
>
>>> Why republish horribly broken code when you aren't going to attempt
>>> to correct it?
>>>
>>> That it compiles is beside the point.
>>>
>>
>> Don't be such a moron all your life Santosh. It compiling is the first
>> step to get Bill to fix his own bugs.
>
> No. Understanding C is the first step.

Sigh. Obviously.

>
> A typical C compiler will gladly accept highly bastardised C and will
> attempt to generate an executable. Fixing errors reported by a compiler
> *after* having learnt the language is one thing, but depending on
> compiler diagnostics to learn the rules and semantics of C is not very
> bright, IMO.

Learning by doing Santosh. its why I recommend using a debugger. Clearly
Bill is incapable of reading code.

The point, which even you in your most "clc reg" mode must see that
fixing the bugs so he can COMPILE the code can only be benefifical. He
could not even match brackets for goodness sake.

Richard

unread,
Aug 4, 2008, 3:11:47 PM8/4/08
to
santosh <santo...@gmail.com> writes:

> Richard wrote:
>> santosh <santo...@gmail.com> writes:
>>> Bill Cunningham wrote:
>
>>>> char **argv is the parameter I am passing to main. isalpha is not
>>>> going to take this. It wants an int. Am I going to have to use atoi
>>>> in here somewhere just to test if something is a char or not?
>>>
>>> No. What is the type of argv[n][n]? Will that be compatible with the
>>> type that isalpha takes?
>>
>> You are wrong. He might well have to use it if the characters are
>> there as part of a command line integer parameter. He needs to convert
>> the character sequence to that integer.
>
> Don't you find it tiresome to disagree just for the sake of it?

I would if that were the reason. But you were wrong. Or appeared to be
wrong.

He asked if he could use atoi in there somewhere. And yes, he can
indeed. Remember we are talking about Bill. You talked about
isalpha. However he still needs the integer values from the chars passed
in.

santosh

unread,
Aug 4, 2008, 3:14:24 PM8/4/08
to
Richard wrote:

The very reason he started this thread was because he *could* *not*
understand the errors and warnings his compiler gave him. And that is a
direct result of the fact that he has only correctly learnt a minuscule
fraction of C (though he incorrectly uses a rather larger portion of
it.)

You need to know the language to understand all but the most simple of
typical compiler messages. Us telling him how to fix the code to shut
the compiler up is no good, since he doesn't understand *why* those
fixes are needed. There really is no alternative for him but to keep
trying from the very beginning of a good tutorial, if he really is
serious about this.

I'm surprised that you advocate this "learning by doing" philosophy for
Bill of all the people. Someone who can't match parenthesis isn't going
to get very far with gdb or gcc. It's better to understand than to
learn.

Keith Thompson

unread,
Aug 4, 2008, 3:43:50 PM8/4/08
to
Keith Thompson <ks...@mib.org> writes:
> "Bill Cunningham" <nos...@nspam.com> writes:
>> "Richard" <rgr...@gmail.com> wrote in message
>> news:g77e50$52s$1...@registered.motzarella.org...
>>
>> Non production code!
>>
>> Yes that's right Richard. Non production meant to be used only by me or I
>> would use exit(EXIT_FAILURE) everytime it is to be used and not the #define
>> ex macro.
>
> In code meant to be used only by you, you can do anything you like.
>
> If you want to post it here and expect to get help, I suggest that you
> drop the "ex" macro and write "exit(EXIT_FILAURE)", so that it's
> easier for us to read your code and offer advice.

I meant "exit(EXIT_FAILURE)", of course.

osmium

unread,
Aug 4, 2008, 3:46:19 PM8/4/08
to
"Bill Cunningham" wrote:

> Here's a reposting of the source.
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <ctype.h>
> #define ex exit(EXIT_FAILURE)
>
> int main (int argc, char *argv[]) {
> if (argc!=4) {
> puts("print usage error");
> ex;
> }
> if (isalpha(argv[1]) || isalpha(argv[2]) {
> puts("print non alpha allowed");

--- snip ---
Someone mentioned the other day that you should cut down the size of your
program to get something more manageable and you said you didn't know how to
do that. Here is your program, cut down and reformatted to one of the
acceptable formats. It does not compile. Can you see why? Fix any
problems and *only then* start adding your original stuff back in, compiling
**very** often. If you get warnings, fix them too or at least understand
what the warnings mean and why the compiler presented them, and consciously
deciding that you can safely ignore any warnings provided.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define ex exit(EXIT_FAILURE)

int main (int argc, char *argv[])
{
if (argc!=4)
{
puts("print usage error");
ex;
}
if (isalpha(argv[1]) || isalpha(argv[2])
{
puts("print non alpha allowed");
ex;
}

return 0;
}


Default User

unread,
Aug 4, 2008, 4:43:55 PM8/4/08
to
santosh wrote:

> Richard wrote:

> > You are wrong. He might well have to use it if the characters are
> > there as part of a command line integer parameter. He needs to
> > convert the character sequence to that integer.
>
> Don't you find it tiresome to disagree just for the sake of it?

Of course not. He is a troll. And you're playing his game -- again.


Brian

Bill Cunningham

unread,
Aug 4, 2008, 6:57:59 PM8/4/08
to

"Keith Thompson" <ks...@mib.org> wrote in message
news:lnd4koa...@nuthaus.mib.org...

> Bill, if you can't get OE Quotefix to work for you, then please pay
> attention when you post a followup. If the article to which you're
> replying was posted through Google Groups, please do *something* to
> indicate the division between the quoted material and your new text.

How do I know if it's posted through google groups ?

Bill


Bill Cunningham

unread,
Aug 4, 2008, 8:03:08 PM8/4/08
to

"Keith Thompson" <ks...@mib.org> wrote in message
news:lnd4koa...@nuthaus.mib.org...
> "Bill Cunningham" <nos...@nspam.com> writes:
>> "William Pursell" <bill.p...@gmail.com> wrote in message
>> news:d32ed3d0-4e12-4b31...@79g2000hsk.googlegroups.com...
>>
>> Assuming gcc & bash, try:
>> $ gcc foo.c 2>&1 | less
>
> Bill, if you can't get OE Quotefix to work for you, then please pay
> attention when you post a followup. If the article to which you're
> replying was posted through Google Groups, please do *something* to
> indicate the division between the quoted material and your new text.

Ok I will start paying attention to the headers and if it says
googlegroups I'll put a line or something somewhere to make things more
readable. I'll get this straightened out.

Bill


Bill Cunningham

unread,
Aug 4, 2008, 8:44:01 PM8/4/08
to

"Anand Hariharan" <mailto.anan...@gmail.com> wrote in message
news:216d96b3-ea73-479b...@c65g2000hsa.googlegroups.com...

Am sure you are following the posts (cf. else-thread by Barry Schwarz,
Santosh, Ian Collins et al.) that have been betting on what exactly
you are doing here?

Actually I haven't been reading all the foolishness but I am aware of what's
going on from reading a couple of posts.
Bill


Richard

unread,
Aug 4, 2008, 8:51:36 PM8/4/08
to
"Bill Cunningham" <nos...@nspam.com> writes:

Why are you duplicating what the previous poster said?

Bill Cunningham

unread,
Aug 4, 2008, 8:59:26 PM8/4/08
to

"Richard" <rgr...@gmail.com> wrote in message
news:g7886q$duo$1...@registered.motzarella.org...

> Why are you duplicating what the previous poster said?

Oh no not again. Posts from google groups screw up my posting Richard for
some reason.

Bill


Keith Thompson

unread,
Aug 4, 2008, 9:11:52 PM8/4/08
to

Check the message headers for any of:

Organization: http://groups.google.com
Message-ID: <ANYTHING.googlegroups.com>
X-Complaints-To: groups...@google.com
Complaints-To: groups...@google.com

Organization is the most likely to be easily accessible.

(Or get OE Quotefix to work properly, but as I mentioned I can't help
you with that.)

Richard Heathfield

unread,
Aug 4, 2008, 9:26:40 PM8/4/08
to
Keith Thompson said:

> "Bill Cunningham" <nos...@nspam.com> writes:
>> "Keith Thompson" <ks...@mib.org> wrote in message
>> news:lnd4koa...@nuthaus.mib.org...
>>
>>> Bill, if you can't get OE Quotefix to work for you, then please pay
>>> attention when you post a followup. If the article to which you're
>>> replying was posted through Google Groups, please do *something* to
>>> indicate the division between the quoted material and your new text.
>>
>> How do I know if it's posted through google groups ?
>
> Check the message headers for any of:

He can't even learn something as simple as printf, and now you're trying to
teach him about NNTP headers?

I admire your futility^Woptimism, but I have a suggestion for you. In
future, don't try to correct his posting style. Such corrections are, in
any case, strictly off-topic. Instead, why not just ignore any article in
which he fails to quote correctly? That way, maybe we can /all/ get some
sleep.

This technique can be extended. By ignoring any article in which he posts
code where the parentheses don't match; where the code is so badly laid
out that it's unreadable; where the question is about diagnostic messages
but the article omits source or messages or both; by ignoring all such
articles, we could perhaps encourage Mr Cunningham to care about these
little details without nagging him all the time. A stony silence can
sometimes be more eloquent than a tedious regurgitation of old complaints.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Nick Keighley

unread,
Aug 5, 2008, 5:42:50 AM8/5/08
to
On 4 Aug, 19:36, Keith Thompson <ks...@mib.org> wrote:

> Bill, if you can't get OE Quotefix to work for you, then please pay
> attention when you post a followup.  If the article to which you're
> replying was posted through Google Groups, please do *something* to
> indicate the division between the quoted material and your new text.

google no longer has this particular problem

--
Nick Keighley

Doug Miller

unread,
Aug 5, 2008, 6:24:22 AM8/5/08
to

Dammit, Bill, will you *please* quote properly??

Keith Thompson

unread,
Aug 5, 2008, 11:25:08 AM8/5/08
to

I know that Google Groups now does proper quoting. This appears to be
a different problem, an interaction between Google Groups and Outlook
Express, the newsreader that Bill is using.

Apparently if you use OE to post a followup to an article that was
posted to Google Groups, OE doesn't quote properly. Something called
"OE Quotefix" is supposed to correct this.

Richard Bos

unread,
Aug 6, 2008, 9:35:19 AM8/6/08
to
Barry Schwarz <schw...@dqel.com> wrote:

> Two possibilities:
>
> This is very true and YOU are wasting our time.
>
> You are having more fun than we can imagine jerking us around and
> WE are wasting our time.

No, one possibility: either Bill is lying or he isn't, it really doesn't
matter which, because you are wasting your time either way.

Richard

Geoff

unread,
May 9, 2010, 3:46:51 PM5/9/10
to
On Sat, 02 Aug 2008 17:45:26 GMT, "Bill Cunningham" <nos...@nspam.com>
wrote:

> Would anyone be interested in giving this a quick look. The compiler
>gave me so many errors I don't know where to start. This is my first use of
>isalpha.
>
>#include <stdio.h>
>#include <stdlib.h>
>#define ex exit(EXIT_FAILURE)
>
>int main(int argc, char *argv[])


>{
> if (argc != 4) {
> puts("print usage error");
> ex;
> }

> if (isalpha(argv[1]) || isalpha(argv[2])) {
> puts("name is 3rd arg");
> ex;
> }
> double x, y;
> FILE *fp;
> x = strtod(argv[1], NULL);
> y = strtod(argv[2], NULL);
> if (fp = fopen(argv[3], "a"))
> == NULL) {
> puts("fopen error");
> ex;
> }
> fprintf(argv[3], "%.2f", x, y);
> if (fclose(fp))
> == NULL) {
> puts("fclose error");
> ex;
> }
> return 0;
>}
>
>I dunno sigh..
>
>Bill
>

Bill,

At the risk of raising this necro-thread to new heights of ridicule, I
offer this observation.

You seem to be enamored of the kinds of idioms and style demonstrated
in K&R C. I regard the style demonstrated above as pathological
idiomitis.

I suggest concentrating less on fancy idioms and short variable names
and more on writing clean C and making it easy to read. Restrict
yourself to one effect per statement and never use assignment in if()
statements. This will reduce your error rate while coding and will
allow the compiler to tell you what's wrong with each statement as it
occurs rather than multiple warnings or errors per line. The KISS
principle applies in all things programmatic.

The time has long since passed where short C is efficient C or even
optimal C. The compilers today can optimize your code so your first
duty is to write clear, maintainable code.

I offer the following as a suggested style for all your future
programs.

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

/*
* This program expects three command line arguments:
* A string of digits, another string of digits
* followed by a file name.
*
* Output is floating point representation of both
* digit strings to two decimal places in the file
* specified in the command line.
*
*/

int main(int argc, char *argv[])
{
double x;
double y;
FILE *fp;

if (argc != 4) {
puts("usage error, not enough arguments");
exit(EXIT_FAILURE);
}

if (isalpha(*argv[1]) || isalpha(*argv[2])) {
puts("name is 3rd arg, args 1 and 2 must be numeric");
exit(EXIT_FAILURE);
}

x = strtod(argv[1], NULL);
y = strtod(argv[2], NULL);

fp = fopen(argv[3], "a");
if (fp == NULL) {
puts("fopen error");
exit(EXIT_FAILURE);
}

fprintf(fp, "%.2f %.2f\n", x, y);

if (fclose(fp) != 0) {
puts("fclose error");
exit(EXIT_FAILURE);
}
return 0;
}


Criticisms of your program:

Your program had an obvious bug in the fprintf call where it fails to
output both numbers but your concentration on idiomatic usage in the
rest of the body of the function obscured it due to all the errors.

Avoid using assignment within if() statements. Your use of this idiom
created errors in your use of parentheses and this created error
diagnostics and warnings non-specific to the parenthesis errors.

Avoid frivolous use of macros.

Comment your intentions.
Comment program input and output.
Comment like you are explaining it to an idiot.
The idiot who will be reading your comments will thank you.
The idiot who will be reading your comments will be you - next year.

Document your code.
The code is not the documentation.
The code is not the specification.

Use white space to improve readability.

One variable per declaration.
Declare variables at the top of the function, not deep inside it.
There are occasions when declaring variables at block scope or near
point of use is advisable, this is not one of them.
If you keep your functions short this should not be a problem.

If function documentation says a function returns 0 if no error, use 0
not NULL. If function documentation says a function returns NULL on
error, check for NULL, not 0.

Include the proper standard header for library functions used in your
program.

Praise of your program:

Good use of function return values.
Good use of error checking.
You checked for argument error conditions at top of function.
Good use of error return from main.

Keith Thompson

unread,
May 9, 2010, 4:31:12 PM5/9/10
to
Geoff <ge...@invalid.invalid> writes:
> On Sat, 02 Aug 2008 17:45:26 GMT, "Bill Cunningham" <nos...@nspam.com>
> wrote:
>> Would anyone be interested in giving this a quick look. The compiler
>>gave me so many errors I don't know where to start. This is my first use of
>>isalpha.
[snip]

> Bill,
>
> At the risk of raising this necro-thread to new heights of ridicule, I
> offer this observation.
[snip]

Geoff, you're responding to an article from nearly two years ago. It
spawned a thread containing, according to Google Groups, 91 articles.

0 new messages