sh?tpile of errors

  • Thread starter Bill Cunningham
  • Start date
K

Keith Thompson

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

Richard

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

--
 
B

Bill Cunningham

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
 
S

santosh

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

santosh

Richard said:
santosh said:
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.
 
R

Richard

santosh said:
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.
 
R

Richard

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

santosh

Richard said:
Sigh. Obviously.


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.

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

Keith Thompson

Keith Thompson said:
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.
 
O

osmium

Bill Cunningham said:
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;
}
 
D

Default User

santosh said:
Richard wrote:

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
 
B

Bill Cunningham

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
 
B

Bill Cunningham

Keith Thompson said:
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
 
B

Bill Cunningham

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
 
R

Richard

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

Why are you duplicating what the previous poster said?
 
B

Bill Cunningham

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
 
K

Keith Thompson

Bill Cunningham said:
How do I know if it's posted through google groups ?

Check the message headers for any of:

Organization: http://groups.google.com
Message-ID: <ANYTHING.googlegroups.com>
X-Complaints-To: (e-mail address removed)
Complaints-To: (e-mail address removed)

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.)
 
N

Nick Keighley

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
 
D

Doug Miller

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

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

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top