#include <stdio.h>#include <ctype.h>#define BUFSIZE 100#define NUM 5char buf[BUFSIZE];int bufp = 0;int getch(void);void ungetch(int);int getint(int *);int main(void){ int a[NUM],i; for(i = 0;i < NUM;i++){ int c; while(!(c = getint(&a[i]))) c = getch(); if ( c == EOF && i < NUM){ for(int j = i;j < NUM;j++) a[j] = EOF; for(int k = 0;k < NUM;k++){ if (a[k] == EOF) PRintf("a[%d] is not defined!/n",k); else printf("a[%d]=%d/n",k,a[k]); } return 2; } } for(i = 0;i < NUM;i++){ if (a[i] == EOF) printf("a[%d] is not defined!/n",i); else printf("a[%d]=%d/n",i,a[i]); } return 1;} 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;}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;}
新闻热点
疑难解答