does snprintf() allocate memory and does it need to be deallocated ?
Code:
char *fileToBeOpened; I couldn't find much information on this from Google ! Kindly guide ! |
"man snprintf" doesn't say so, so why do you think snprintf will allocate some memory?
|
Thanks for replying !
Yes, man snprintf doesn't say so, that's why I asked here. variable 'fileToBeOpened' is a char*, so does the data stored in variable 'FILEPATH' gets stored in memory and 'fileToBeOpened' just points to it ? Is it so ? |
Hey,
Quote:
The alternative to snprintf would be asprintf/asnprintf which allocates memory for you. In this case, you would then have to call free for the returned memory address. BUT, keep in mind that asprintf/asnprintf is NOT part of the C99 standard (or any C standard), though you can't rely on the portibility of this function ... Hope that helps, - Andi - |
Quote:
- Andi - |
Quote:
If there is no allocation, Where do these 10 characters get stored then ? (I mean how do they get stored in the variable 'fileToBeOpened') Please explain more ! (I am sorry if it is a dumb question) |
Quote:
I did overlook the fact that I unless I myself allocate memory to the variable 'fileToBeOpened' the above shown code will give me a segmentation fault !!!! |
All times are GMT -5. The time now is 11:00 PM. |