注册 登录
编程论坛 C图形专区

请各位看看,帮忙指点指点 关于指针的问题

saihuo092617 发布于 2013-05-11 16:29, 806 次点击
/#include <stdio.h>
#include <ctype.h>
#define BUFSIZE 100

int getch(void);
void ungetch(int);
int getint(int * );

char buf[BUFSIZE];
int bufp = 0;

int main (void)
{
    int n, array[10];

    for(n = 0; n < 10 && getint(&array[n]) != EOF; n++)
        printf("%d\n",array[n]);
}

int getint(int * pn)  /* getint函数: 将输入中的下一个整数赋值给 *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;
}

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;
}

在getint 函数中为什么return c; 能返回一个数,我输入123时,输出123,他不是应该返回最后的一个数字3么?
0 回复
1