I'm trying to input an array length from user, and the output the numbers..
I get only "1", "1", "1" as output when n = 3, and num's values are integers.
int main()
{
int *arr1, n,num = 0,*p;
printf("Please enter the size of the array: ");
scanf("%d", &n);
arr1 = (int*)malloc(n * sizeof(int));
if (arr1 == NULL)
printf("Not enough memory\n");
else printf("Array was allocated!\n" );
for (p = arr1; p < arr1 + n; p++)
{
*p = scanf("%d", &num);
printf("%d ", *p);
}
free(arr1);
getch();
}
scanfcorrectly one time, why not the second?