c point ccccc

时间:2022-08-18 15:42:46

代码来自《K&R》

范例输入(控制台):

-32 23 11 18
33987 23
^Z

范例输出:

-32
23
11
18
33987
23

#include<stdio.h>
#define SIZE 100 int main()
{
int n, array[SIZE], getint(int *); for(n = ; n < SIZE && getint(&array[n]) != EOF; n ++)
;
for(int i = ; i < n; i ++)
printf("%d\n", *(array+i));
return ;
} #include<ctype.h> 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 ;
}
sign = (c == '-')? - : ;
if(c == '+' || c == '-')
c = getch();
for(*pn = ; isdigit(c); c = getch())
*pn = * *pn + (c - '');
*pn *= sign;
if(c != EOF)
ungetch(c);
return c;
} #define BUFSIZE 100 char buf[BUFSIZE];
int bufp = ; int getch(void)
{
return (bufp > )? buf[--bufp] : getchar();
} void ungetch(int c)
{
if(bufp >= BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}