P
pereges
btw i want to read a string containing 3 numbers:
"1234 3333 6666"
SO the logic I used was
unsigned long l1, l2, l3;
char s[] = "1234 3333 6666";
char *endptr1, *endptr2, *endptr3;
errno = 0;
l1 = strtoul(s, &endptr1, 10);
l2 = strtoul(&endptr1, &endptr2, 10);
l3 = strtoul(&endptr2, &endptr3, 10);
if (errno == ERANGE)
{
if (l1 == ULONG_MAX || l2 == ULONG_MAX || l3 == ULONG_MAX)
{
/* do the error handling */
}
}
else
{
if (s == endptr1 || endptr1 == endptr2 || endptr2 == endptr3)
{
printf("Conversion failed");
return (1);
}
}
"1234 3333 6666"
SO the logic I used was
unsigned long l1, l2, l3;
char s[] = "1234 3333 6666";
char *endptr1, *endptr2, *endptr3;
errno = 0;
l1 = strtoul(s, &endptr1, 10);
l2 = strtoul(&endptr1, &endptr2, 10);
l3 = strtoul(&endptr2, &endptr3, 10);
if (errno == ERANGE)
{
if (l1 == ULONG_MAX || l2 == ULONG_MAX || l3 == ULONG_MAX)
{
/* do the error handling */
}
}
else
{
if (s == endptr1 || endptr1 == endptr2 || endptr2 == endptr3)
{
printf("Conversion failed");
return (1);
}
}