Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using calloc

Status
Not open for further replies.

tan6262

Programmer
Nov 1, 2000
3
US
how would i use calloc to allocate memory for a 2-D array outside of main. in main are: int rows, int cols, and int **array. the values for rows and cols were inputed by the user in a separate function also outside of main. so far i have:
int function (int *rows, int *cols, int ***array)
{
int i;
if(!(*array = (int **) calloc (*rows, sizeof (int *))))
{
printf("error message");
return 1;
for (i = 0; i < *rows; i++)
if(!(*(array + i) = (int **) calloc (*cols, sizeof (int *))))
{
printf(&quot;error message&quot;);
return 1;
}
}
return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top