关于函数getint()取得一个int数字的返回值
为什么选择返回c?程序代码:
程序代码: 1 #include <stdio.h>
2 int getch(void);
3 void ungetch(int);
4 int getint(int *pn)
5 {
6 int c,sign;
7 while(isspace(c=getch())) //跳过空白符
8 ;
9 if(!isdigit(c)&&c!=EOF&&c!='+'&&c!='-')
10 {
11 ungetch(c); //将字符压回,跳出函数
12 return 0;
13 }
14 sign=(c=='-')? -1:1; //判断正负
15 if(c=='+'||c=='-')
16 c=getch(); //c=='+'或'-'再读入一位
17 for(*pn=0;isdigit(c);c=getch()) //按个十百千累加数值
18 *pn=10**pn+(c-'0');
19 *pn*=sign; //加上正负号
20 if(c!=EOF) //多读入的一位若不是结束标识符则压回作下一次运算
21 ungetch(c);
22 return c; //返回一个数
23 }
~ 
