fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6. int indice = 0, indiceParcial = 0;
  7. int *vetor = malloc(sizeof(int) * 10);
  8. while (1) {
  9. int valor;
  10. scanf("%d", &valor);
  11. if (valor == 0) break;
  12. vetor[indice++] = valor;
  13. if (indiceParcial++ == 9) {
  14. int *vetorAuxiliar = malloc(sizeof(int) * (indice + 10));
  15. memcpy(vetorAuxiliar, vetor, indice * sizeof(int));
  16. free(vetor);
  17. vetor = vetorAuxiliar;
  18. indiceParcial = 0;
  19. }
  20. }
  21. printf("\n");
  22. for (int i = 0; i < indice; i++) printf("%d ", vetor[i]);
  23. }
Success #stdin #stdout 0s 4424KB
stdin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
stdout
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21