"chellappa" <N.*********@gmail.com> writes:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
long value;
char src[]="71";
char *err;
errno = 0;
value = strtol(src, &err, 8);
perror("strtol");
printf("%ld %ld\n", value, LONG_MAX);
printf("%d\n", *err);
return 0;
}
"err" is a poor name for something to be used for the second argument
in a call to strtol().
You call perror() without checking whether there was actually an
error.
The program interprets the string "71" as an octal number. I suppose
that might be a useful thing to do in some circumstances, but I'm at a
loss to understand the point.
The article to which you're responding asked about finding the length
of a string. Your program doesn't do that.
As usual, you've posted without providing any context from the
previous article.
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.