Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct elem{
- int *vect;
- int lenght;
- };
- typedef struct elem array;
- typedef array *Array;
- Array newArray();
- void insert(Array, int);
- void stampa(Array);
- int main()
- {
- int i, n, x;
- Array a = newArray();
- printf("Quanti elementi?");
- scanf("%d", &n);
- for(i = 0; i < n; i++){
- printf("Elemento n.%d: ", i+1);
- scanf("%d", &x);
- insert(a,x);
- }
- stampa(a);
- return 0;
- }
- Array newArray(){
- Array new = (Array)malloc(sizeof(array));
- new->vect = (int *)malloc(sizeof(int));
- new->lenght = 0;
- return new;
- }
- void insert(Array a, int elem){
- a->lenght++;
- a->vect = (int *)realloc(a->vect,a->lenght * sizeof(int));
- a->vect[a->lenght-1] = elem;
- }
- void stampa(Array a){
- int i;
- for(i = 0; i < a->lenght; i++)
- printf("%d -> ", a->vect[i]);
- printf("STOP.\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement