Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Help, about programming, how to input plastic arrays of arbitrary length.
Help, about programming, how to input plastic arrays of arbitrary length.
Assume that C language is used. It is assumed that an integer value is entered until a value of 0 is entered.

Use dynamic allocation. Increase memory allocation with realloc. The complete process is as follows:

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

int main()

{

Int input, n;

int count = 0;

int * numbers = NULL

int * more _ numbers = NULL

Do {

Printf ("Enter integer value (0 to end):");

Scanf ("%d ",& input);

count++;

more _ numbers =(int *)realloc(numbers,count * sizeof(int));

If (more _ numbers! =NULL) {

Numbers = More _ Numbers;

Numbers[count- 1]= input;

}

Otherwise {

Free (digital);

Puts ("memory is (re) allocated incorrectly");

Exit (1);

}

} while (enter! =0);

Printf ("Number entered:");

for(n = 0; N< count; n++) printf ("%d ",numbers[n]);

Free (digital);

Returns 0;

}