char f1(double arg1, int n, struct mytype *arg2)
{
//some code here
arg2 = (struct mytype*)malloc((size_t)(n*sizeof(struct mytype));
//some code here
return 0;
}
and my main function is like this
int main()
{
struct mytype *var1;
char c;
double d = 20;
int n = 10;
//some code here
c = f1(d, n, var1);
//some code here;
return 0;
}
Now running this code (in Visual Studio 2010) caused a run time error because I passed the variable var1 into the function without initializing it. However, I want f1 to allocate memory to it. This version of the program works:
char f1(double arg1, int n, struct mytype *arg2)
{
//some code here
return 0;
}
int main()
{
struct mytype *var1;
char c;
double d = 20;
int n = 10;
//some code here
arg2 = (struct mytype*)malloc((size_t)(n*sizeof(struct mytype));
c = f1(d, n, var1);
//some code here;
return 0;
}
But is it possible to allocate memory to a pointer the way I want to like in the first case?
Thanks in advance
This post has been edited by Louisda16th: 18 May 2010 - 12:27 PM

New Topic/Question
Reply



MultiQuote







|