sh?tpile of errors

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

\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
 
R

Richard

Richard Heathfield said:
[Quoting marks fixed]

Bill Cunningham said:
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.
 
B

Bill Cunningham

[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
 
K

Keith Thompson

Bill Cunningham said:
Jens Thoms Toerring said:
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.

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.
 
C

CBFalconer

Bill said:
Jens Thoms Toerring said:
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.
 
E

Edward A. Falk

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

santosh

Keith Thompson wrote:

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.
 
C

Chris M. Thomasson

B

Barry Schwarz

Bill Cunningham said:
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?
 
B

Barry Schwarz

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.
 
S

santosh

Barry said:
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".
 
I

Ian Collins

Barry said:
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.
 
S

santosh

Ian said:
My money's on number 2.

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.
 
D

Default User

santosh said:
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
 
S

Serve Lau

Bill Cunningham said:
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
 
K

Keith Thompson

Malcolm McLean said:
Bill Cunningham said:
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, for an integer value i, is a pointer to a string. You
can use it like this:
printf("argv = %s\n", argv);
or, if you can handle a slightly more sophisticated use of printf:
printf("argv[%d] = %s\n", i, argv);

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

The syntax ``argv[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);
for (j = 0; argv[j] != '\0'; j ++) {
printf(" argv[%d][%d] = '%c'\n", i, j, argv[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.
 
B

Bill Cunningham

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
 
B

Bill Cunningham

[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
 

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

Similar Threads

code question 74
code 50
Command Line Arguments 0
I'm facing a run-time error 14
seg fault 76
pow type problem 6
How can I view / open / render / display a pdf file with c code? 0
percentage 8

Members online

No members online now.

Forum statistics

Threads
474,099
Messages
2,570,626
Members
47,237
Latest member
David123

Latest Threads

Top