On Mon 2008-12-01 20:38:10 UTC-0800, Titi Anggono ([EMAIL PROTECTED]) wrote:
> I allocated memory to one array, which stores data from one file, and > I made a condition that if one data being read using fscanf() is > larger than the threshold value the program close. It's a good idea to use fgets(), where you can specify a maximum number of characters to read. If you malloc() 42 bytes then tell fgets() to read 42 bytes, it is impossible to overflow the buffer, so is very safe. > I just read that it is our responsibility to release the memory if it > is not required. Oke, I understand that and I can put free() at the > end of the code. But, I made a condition so I put exit() before the > free(). I wonder if? exit() frees the memory or I have to put free() > also inside the condition. If you put exit() before free() then the call to free() will never be executed. Ordinarily when your program exits, any memory it allocated will be freed. Still, freeing memory as soon as you've finished with it is a good habit to get into, particularly as your programs get larger (or if you work with large amounts of data).
