sh?tpile of errors

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

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

Keith Thompson

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

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

Bill Cunningham

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
 
B

Bill Cunningham

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
 
R

Richard

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

--
 
R

Richard

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

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!
 
B

Bill Cunningham

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
 
B

Bill Cunningham

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

F?ck off.
 
S

santosh

Richard 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");
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.
 
A

Anand Hariharan

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, for an integer value i, is a pointer to a string.
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
 
B

Bill Cunningham

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
 
R

Richard

santosh said:
Richard 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");
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.

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

Bill Cunningham

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
 
K

Keith Thompson

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

Keith Thompson

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

"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[].
 
S

santosh

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

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top