pointer to int error

B

Bill Cunningham

I know I'm not seeing something here I should be. Where am I screwing
up?

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

int sum(int x, int y)
{
return x + y;
}
int dice(int i)
{
srand(time(NULL));
printf("%i\n", rand() % i);
return 0;
}

int main(int argc, char *argv[])
{
if (argc == 1 || argv > 4) {
fputs("dice gen usage error\n", stderr);
exit(EXIT_FAILURE);
}
di.c: In function `main':
di.c:18: warning: comparison between pointer and integer
di.c:21: error: syntax error at end of input

Here's the compiler errors.

Bill
 
B

Bill Cunningham

Stefan Ram said:
What's the type of »argv«, and what's the type of »4«?
I know where the error is. argv is either char* or char**. and 4 is an
int as the compiler says. I've had this same trouble before and forgot how
to handle it. I don't want to cast, that's cheating.

Bill
 
S

Stefan Ram

Bill Cunningham said:
I know where the error is. argv is either char* or char**. and 4 is an
int as the compiler says. I've had this same trouble before and forgot how
to handle it. I don't want to cast, that's cheating.

I see. You might post what this line is supposed to mean
(not with the error, but what you actually want to
express with this expression) in English (we can only
read your code above, but not your intention).

If you can not write it in C, you might be able to
write it in English.
 
B

Bill Cunningham

I see. You might post what this line is supposed to mean
(not with the error, but what you actually want to
express with this expression) in English (we can only
read your code above, but not your intention).

If you can not write it in C, you might be able to
write it in English.

If the program is run from the command line with no arguments the error
is triggered. Hence argc==1. If there are more than four arguments on the
line the error is triggered. Hence,
argv[0], argv[1], argv[2], and argv[3] are allowed. But no more than
argv[4].

Bill
 
S

Stefan Ram

Bill Cunningham said:
If the program is run from the command line with no arguments the error
is triggered. Hence argc==1. If there are more than four arguments on the
line the error is triggered. Hence,
argv[0], argv[1], argv[2], and argv[3] are allowed. But no more than
argv[4].

I see. I believe the solution to your problem is to use
»argc« also for the comparison with »4«, just as you used
it in the comparison with »1«.
 
B

Bill Cunningham

I see. I believe the solution to your problem is to use
»argc« also for the comparison with »4«, just as you used
it in the comparison with »1«.

Now see I would never have thought of that. Simply because I have just
started using argc. And I have used *(argv[]) to do this exact same thing
before if I am remembering right. But I only recently started using argument
count I have always used argument vector.

Bill
 
B

Bill Cunningham

Stefan Ram said:
I see. I believe the solution to your problem is to use
»argc« also for the comparison with »4«, just as you used
it in the comparison with »1«.

I see thanks Stefan.

B
 
B

Barry Schwarz

Bill Cunningham said:
If the program is run from the command line with no arguments the error
is triggered. Hence argc==1. If there are more than four arguments on the
line the error is triggered. Hence,
argv[0], argv[1], argv[2], and argv[3] are allowed. But no more than
argv[4].

I see. I believe the solution to your problem is to use
»argc« also for the comparison with »4«, just as you used
it in the comparison with »1«.

You've been suckered. He had this problem solved in his previous
thread, "pointer arithmetic error?", started on 4 Dec. He just likes
to see how many fish he can reel in.
 
S

Seebs

You've been suckered. He had this problem solved in his previous
thread, "pointer arithmetic error?", started on 4 Dec. He just likes
to see how many fish he can reel in.

It's hard to tell. He acts a lot like he has mild (comparatively)
alexia, and simply can't read/copy/write correctly -- and he's repeatedly
talked about getting an error message, not comprehending it, and just
changing stuff at random to see if it makes the error message change.

-s
 
G

gwowen

It's hard to tell.  He acts a lot like he has mild (comparatively)
alexia, and simply can't read/copy/write correctly

Oh goody. An over-the-internet psychological/neuropathological
diagnosis, from someone who has no training in psychology or
neurology. They're *always* worthwhile.
 
S

Seebs

Oh goody. An over-the-internet psychological/neuropathological
diagnosis, from someone who has no training in psychology or
neurology. They're *always* worthwhile.

Three points:
1. Not a diagnosis in any clinical sense, obviously.
2. It's not as though it's hard to identify some things. You can also
spot some other common things with some accuracy -- I got a ton of
internet diagnoses in the past, and sure enough, they match what the people
with the specialized training say. If someone posts about the eight projects
they started (five of which they finished) in the last day or so, continues
doing that for about a week, then disappears for a month, and comes back
later saying "I dunno, I guess I played a bunch of WoW and read some books",
you do NOT need a degree to figure out what's involved, usually.
3. What makes you think I have no training in psychology or neurology?

-s
 
S

Squeamizh

It's hard to tell.  

No, it's really not hard at all, and no sophisticated psychoanalysis
is necessary. I would, however, like to extend my heartfelt
appreciation for providing such an amusing post!
 
B

Barry Schwarz

It's hard to tell. He acts a lot like he has mild (comparatively)
alexia, and simply can't read/copy/write correctly -- and he's repeatedly
talked about getting an error message, not comprehending it, and just
changing stuff at random to see if it makes the error message change.

Except he doesn't have these problems when he posts to groups where he
is really interested in the answer.
 
K

Keith Thompson

Barry Schwarz said:
Except he doesn't have these problems when he posts to groups where he
is really interested in the answer.

What groups in particular? I recently checked, but didn't see much
to support your statement (I didn't spend much time on it).
 
B

Barry Schwarz

What groups in particular? I recently checked, but didn't see much
to support your statement (I didn't spend much time on it).

Most recently microsoft.public.windowsxp.general.
 
S

Seebs

Except he doesn't have these problems when he posts to groups where he
is really interested in the answer.

Interesting. It's sometimes hard to tell a genuine idiot from a careful
imitation. (This is a near variant of Poe's Law.)

-s
 
K

Keith Thompson

Barry Schwarz said:
Most recently microsoft.public.windowsxp.general.

Hmm. I just took a look at a few of his recent postings there, and
his mindset seemed to me to be similar to when he posts here.
 
D

Default User

Seebs said:
Interesting. It's sometimes hard to tell a genuine idiot from a
careful imitation. (This is a near variant of Poe's Law.)

I don't think it matters. He's either trolling or is incapable of
learning C. If you look back, he's supposedly been studying it since at
least 2003. If he's no farther along by now, he never will get there.



Brian
 

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

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top