Originally Posted by
Salem
Well what_is_it is a char pointer.
what_is_it[0] is the first char.
isdigit(what_is_it[0]) would test the first char.
nope didn't work:
Code:
dia/data/wallpaper
main 1
seconds or minutes in comming w3m
in getopts 0 // comes back zero
change time 300 // gets set to function calling to set default
Code:
int seconds_or_minutes(char *what_is_it)
{
printf("seconds or minutes in comming %s\n",what_is_it);
const char sec = 's';
const char min = 'm';
char str1[1+strlen(what_is_it)];
strcpy(str1, what_is_it);
if (isdigit(what_is_it[0]))
{
printf("is not a number\n");
exit(1);
}
if ( strrchr(what_is_it, sec) )
{
return (atoi( strtok(str1, "s") ));
}
if( strrchr(what_is_it, min) )
{
return (atoi(strtok(str1,"m")) * 60);
}
printf(" seconds or minutes outgoing not return %s\n",what_is_it);
//defaults to seconds
return atoi(what_is_it);
}
this worked though
Code:
if (isdigit(what_is_it[1]))
{
printf("is not a number %s\n",what_is_it);
exit(1);
}
results
Code:
main 1
seconds or minutes in comming w3m
is not a number w3m <-- caught it