Is there any C library function to check to see if the command line argument is a numerical value or string?
char *ms = av[i];
//how can i check to see if ms is a numerical value?
if ( ms == NULL ) exit(1);
Thanks
Is there any C library function to check to see if the command line argument is a numerical value or string?
char *ms = av[i];
//how can i check to see if ms is a numerical value?
if ( ms == NULL ) exit(1);
Thanks
Command line arguments are always strings.
To check whether it is numeric or not, I'd suggest you use the strtol() function, and check its various return results.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Be careful though. I think that that returns 0 if the string is not numeric, i.e. you couldn't tell if you had 0 or garbage.
Maybe check isdigit for each character if you're looking for an integer.
You're thinking of the rather dumb atoi(), which returns 0 on error
strtol() returns a status value in errno, and the end pointer points to the first char after the string.
Both of these taken together should be enough to classify any string as numeric or not.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]