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. {
  26. int c, sign;
  27.  
  28. *pn = 0;
  29. while (isspace(c = getch()))
  30. ;
  31. if (!isdigit(c) && c != EOF && c != '+' && c != '-') {
  32. /* ungetch(c);*/ /* if returned to input we fill the array */
  33. return 0;
  34. }
  35. sign = (c == '-') ? -1 : 1;
  36. if (c == '+' || c == '-') {
  37. c = getch();
  38. if (!isdigit(c)) {
  39. ungetch(sign == 1 ? '+' : '-');
  40. return 0;
  41. }
  42. }
  43. while (isdigit(c)) {
  44. *pn = 10 * *pn + (c - '0');
  45. c = getch();
  46. }
  47. *pn *= sign;
  48. if (c != EOF)
  49. ungetch(c);
  50.  
  51. return c;
  52. }
  53.  
  54. int bufp = 0;
  55. int buf[MAX];
  56.  
  57. int getch(void)
  58. {
  59. return bufp > 0 ? buf[--bufp] : getchar();
  60. }
  61.  
  62. void ungetch(int c)
  63. {
  64. if (bufp < MAX)
  65. buf[bufp++] = c;
  66. }
Success #stdin #stdout 0s 2116KB
stdin
1
2
3
z
y
s
stdout
1
2
3
0
0
0