Here's a long-ish shot..........check it out: (C HELP)

MAME

Banned
Sep 19, 2003
9,281
1
0
I'm parsing the command line and part of the specs is that after a '-s', there should be a number specifying the start byte (doesn't matter what it's for...only that I'm supposed to get a # afterwards).

so I got this:
int main(int argc, char *argv[])
.
.
for(i = 1; i < argc; i++)
.
.
if(strcmp(argv, "-s") == 0)
{
i++;
if(isdigit( (int) argv) ) <-------- PROBLEM
start = (int)argv;
else
{
printf("\n\nIllegal arguments, exiting now\n\n");
exit(1);
}
}

I tried to convert the input to an int but that's no good because it converts and char in to an int which is then saved as my start bit. So the letter 'd' would be whatever the ascii code is (I think) as opposed to printing the error message and qutting.

So I guess isdigit isn't the best function, anyone have ideas about this??
 

Heisenberg

Lifer
Dec 21, 2001
10,621
1
0
Originally posted by: MichaelD
Engrish?
MAME is coding on a Friday night instead of drinking heavily and having one night stands like normal, healthy college kids should.
 

MichaelD

Lifer
Jan 16, 2001
31,528
3
76
Originally posted by: Heisenberg
Originally posted by: MichaelD
Engrish?
MAME is coding on a Friday night instead of drinking heavily and having one night stands like normal, healthy college kids should.

Ah...Now I get it. See, after I saw this:
I'm parsing the command line and...

I should've just realized THAT was the problem right there....nobody should be "parsing a command line" on a Friday night!
rolleye.gif


You need to find you a honey, MAME and tell her:

Parse THIS, baby...it's my BoomStick!

:D
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: MichaelD
Originally posted by: Heisenberg
Originally posted by: MichaelD
Engrish?
MAME is coding on a Friday night instead of drinking heavily and having one night stands like normal, healthy college kids should.

Ah...Now I get it. See, after I saw this:
I'm parsing the command line and...

I should've just realized THAT was the problem right there....nobody should be "parsing a command line" on a Friday night!
rolleye.gif


You need to find you a honey, MAME and tell her:

Parse THIS, baby...it's my BoomStick!

:D

hahaha, rock on. My gf is in japan so no sex for me :(
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: ThisIsMatt
Check the next arg one char at a time.

ohhh, hmm...I might be able to do that. How do I see the next char? argv[ 0-length of argv ]...?
 

ThisIsMatt

Banned
Aug 4, 2000
11,820
1
0
Originally posted by: MAME
Originally posted by: ThisIsMatt
Check the next arg one char at a time.

ohhh, hmm...I might be able to do that. How do I see the next char? argv[ 0-length of argv ]...?
Once you determine if the argument -s is there, advance to the next arg. Loop around the arg until you reach the null termination, checking each char with isdigit. You'd loop on something like arg[2][ i] where i runs from 0 to '\0'
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: MAME
Originally posted by: ThisIsMatt
Check the next arg one char at a time.

ohhh, hmm...I might be able to do that. How do I see the next char? argv[ 0-length of argv ]...?


JESUS CHRIST, posting code here is impossible!

that SHOULD read:
argv [ 0 - length of argv(i) ]

(replace the (,)'s with [,]'s)
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: ThisIsMatt
Originally posted by: MAME
Originally posted by: ThisIsMatt
Check the next arg one char at a time.

ohhh, hmm...I might be able to do that. How do I see the next char? argv[ 0-length of argv ]...?
Once you determine if the argument -s is there, advance to the next arg. Loop around the arg until you reach the null termination, checking each char with isdigit. You'd loop on something like arg[2] where i runs from 0 to '\0'


yeah, that's what I was trying to convey on that last post, but fusetalk doesn't like code
 

Chu

Banned
Jan 2, 2001
2,911
0
0
Originally posted by: ThisIsMatt
or aim

postcount++

This code should help your out. This assumes there is only one arg after -s, but you can probably easily extend it.

#include <errno.h>

int tmp;
extern int errno;

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

if (!strcmp(argv[1], "-s")){

tmp = atoi(argv[2]);
if (tmp == 0){
if (errno == ERANGE)
printf("The value is out of range\n");
else if (errno = EINVAL){
printf("That isn't a number dumbass\n");
}
}
}

/* if strcmp failed, check error codes here */

printf("%d\n",tmp);
}


If you have any questions, reply. If your wondering how I knew the error codes for atoi, remember, man pages are your friend!.

-Chu
 

MAME

Banned
Sep 19, 2003
9,281
1
0
thanks chu but I got it already (thanks to matt and ameesh). NOTE: the code I posted was NOT the code that I meant to post. [ i ] makes it go to itallics so a lot of my code is missing and I look like an idiot when I'm actually only a semi-moron!

thanks though