It has been a long time since I have done any programming, and so my knowledge is quite rusty. Say I had a function where I did something like this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void foo(char **txt_ptr)
{
enum {
BUF_MAX = 25
};
char *buffer = malloc(BUF_MAX * sizeof *buffer);
if (buffer == NULL) {
puts("No memory for you!");
exit(EXIT_FAILURE);
}
strcpy(buffer, "A random string");
*txt_ptr = buffer;
}
int main(void)
{
char *textp = NULL;
foo(&textp);
printf("\n%s\n\n", textp);
return 0;
}
Would I do
from main? Would this properly free the memory I allocated in 'foo'?