I'm reading this wonderful book called The C Programming Language 2nd Edition and I'm having a hard time understanding how to use this function that is on page 97. Here it is:
Code:
int getint(int *pn)
{
int c, sign;
while (isspace(c = getch()))
;
if (!isdigit(c) && c != EOF && c != '+' && c != '-') {
ungetch(c);
return 0;
}
sign = (c == '-') ? -1 : 1;
if (c == '+' || c == '-')
c = getch();
for (*pn = 0; isdigit(c); c = getch())
*pn = 10 * *pn + (c - '0');
*pn *= sign;
if (c != EOF)
ungetch(c);
return c;
}
Can someone show me an example of this function in action and also explain what is up with
Code:
for (*pn = 0; isdigit(c); c = getch())
*pn = 10 * *pn + (c - '0');
? I just don't get these two lines. Thanks a lot.