Dynamically allocating memory for const char string using malloc()
问题 I am writing a program that reads a value from an .ini file, then passes the value into a function that accepts a PCSTR (i.e. const char *). The function is getaddrinfo() . So, I want to write PCSTR ReadFromIni() . To return a constant string, I plan on allocating memory using malloc() and casting the memory to a constant string. I will be able to get the exact number of characters that were read from the .ini file. Is that technique okay? I don't really know what else to do. The following