fork(1) download
  1. #include <stdio.h>
  2. #include <ctype.h> /* for isdigit(c), etc. */
  3.  
  4. #define MAX 10
  5. #define SIZE 15
  6.  
  7. int getint(int *pn);
  8.  
  9. int main(void){
  10. int n, k;
  11. int array[SIZE];
  12.  
  13. for(n = 0; n < SIZE && getint(&array[n]) != EOF; n++)
  14. ;
  15. for(k = 0; k < n; k++)
  16. printf("%d\n", array[k]);
  17. scanf("%d", &k);
  18. }
  19.  
  20. int getch(void);
  21. void ungetch(int c);
  22.  
  23.  
  24. int getint(int *pn){
  25. int c, sign;
  26.  
  27. while(isspace(c = getch()));
  28. if(!isdigit(c) && c != EOF && c != '+' && c != '-')
  29. return 0;
  30. sign = (c == '-') ? -1 : 1;
  31. if(c == '-' || c == '+'){
  32. c = getch();
  33. if(!isdigit(c)){
  34. ungetch((sign == 1) ? '+' : '-');
  35. return 0;
  36. }
  37. }
  38. for(*pn = 0; isdigit(c); c = getch())
  39. *pn = 10 * (*pn) + (c - '0');
  40. *pn *= sign;
  41. if(c != EOF){
  42. ungetch(c);
  43. }
  44. return c;
  45. }
  46.  
  47. int bufp = 0;
  48. int buf[MAX];
  49.  
  50. int getch(void)
  51. {
  52. return bufp > 0 ? buf[--bufp] : getchar();
  53. }
  54.  
  55. void ungetch(int c)
  56. {
  57. if (bufp < MAX)
  58. buf[bufp++] = c;
  59. }
Success #stdin #stdout 0s 2116KB
stdin
1
2
3
z
y
s
stdout
1
2
3
-1
0
-1218536476