书上的一段代码中的return
一下代码是C程序设计语言第四章的一段。main()函数是我自己写的,书上的示例代码只有3个getch() ungetch() getint()三个函数。
getint()中为什么要return c,想了半天都没想明白。
从代码上来看不是应该return 1或者return EOF吗?
程序代码:#include <ctype.h>
#include <stdio.h>
#define max_index(x,y) x = y;
int getint(int *pn);
int main(void)
{
int n,k;
int array[100];
for(n = 0; n < 100 && getint(&array[n]) != EOF; n++)
;
max_index(k,n);
for(n = 0; n >=0 && n < k; n++)
printf("%d%c",array[n],!((n+1)%8)?'\n':' ');
return 0;
}
int getch(void);
void ungetch(int);
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;
}
#define BUFSIZE 100
char buf[BUFSIZE];
int bufp = 0;
int getch(void)
{
return (bufp>0)?buf[--bufp]:getchar();
}
void ungetch(int c)
{
if(bufp >= BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}









