fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int main(){
  4. int *ar,c,len,tmp,i,res;
  5. c=0;
  6. len=10;
  7. ar=(int *)calloc(10,sizeof(int));
  8. while(1){
  9. if(c<len){
  10. scanf("%d",&tmp);
  11. if(tmp!=42)
  12. ar[c]=tmp;
  13. else
  14. break;
  15. c++;
  16. }
  17. else{
  18. ar=(int *)realloc(ar,10*sizeof(int));
  19. len+=10;
  20. }
  21. }
  22. for(i=0;i<c;i++)
  23. printf("%d\n",ar[i]);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 2292KB
stdin
1
2
3
4
5
6
7
8
9
6
65756
234
42
33
55
454
3333
stdout
1
2
3
4
5
6
7
8
9
6
65756
234