S
stevenruiz
Hello Everyone,
I am unsure on how to use free() in my function. An example is
below:
main.c
int main()
{
char values[123];
while(getchar() != 'x')
{
read(0, &values, sizeof(values))
function_1(values)
}
}
test.c
char** function_1(char *values)
{
char *values[200];
char** accessValues;
//other code....
values[0] = malloc(123 * sizeof(char *));
accessValues = malloc(123 * sizeof(char *));
accessValues = values;
return accessValues;
}
Please disregard some of the naming conventions. If I am performing
operations on values variable only in the function, but I loop over
the function constantly, where do I free() memory? How would this be
accomplish assuming memory must be freed in a function as opposed to
operations only done in a main? Any help would be appreciated.
I am unsure on how to use free() in my function. An example is
below:
main.c
int main()
{
char values[123];
while(getchar() != 'x')
{
read(0, &values, sizeof(values))
function_1(values)
}
}
test.c
char** function_1(char *values)
{
char *values[200];
char** accessValues;
//other code....
values[0] = malloc(123 * sizeof(char *));
accessValues = malloc(123 * sizeof(char *));
accessValues = values;
return accessValues;
}
Please disregard some of the naming conventions. If I am performing
operations on values variable only in the function, but I loop over
the function constantly, where do I free() memory? How would this be
accomplish assuming memory must be freed in a function as opposed to
operations only done in a main? Any help would be appreciated.