hello i m supposed to make a program that should allocate according to va_start then allocate according to num of parameter specified by first parameter i did everything according but i only got first 2 members of the arguments
Code:
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#define ParseSize(x) (x) + (sizeof x/sizeof x[0])
int * new_i_arrays(int lim,...)
{
va_list ap; // declare object to hold arguments
int *arr;
int i;
va_start(ap, lim); // initialize ap to argument list
arr=(int*)calloc(lim,sizeof(int));
for (i = 0; i < lim; i++)
arr[i] = va_arg(ap, int); // access each item in argument list
va_end(ap); // clean up
return arr;
}
void ShowArr(int *arr,int *Size) {
while( arr < Size )
printf("%d\n",*arr++);
putchar('\n');
}
int main(void)
{
int *p1;
int *p2;
p1=new_i_arrays(5,1,2,3,5,7);
p2=new_i_arrays(3,1,2,3);
ShowArr(p1,ParseSize(p1));
ShowArr(p2,ParseSize(p2));
free(p1);//free allocated memory
free(p2);//free alocated memory
return 0;
}