dynamic memory allocation C - Malloc, How to print out user inputted array.
Go to solution
Solved by Mira Yurizaki,
The scanner loop should be outside the for-loop and the array printer should come after the scanner at some point. Basically:;
for (i = 0; i < k; i++)
{
printf("Value at postion %i: ", i);
scanf("%i", &array[i]);
}
for (j = 0; j < k; j++)
{
printf("%in" ,array[j]);
}
(also not sure why you started at 1, but I haven't used malloc in ever so if it really needs to start at 1, ignore my changes)

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now