String handling in ANSI C (Memory Allocation) -
How can it be that I can specify a string * variable a string, and no need to allocate memory is?
For example, if I have a function, then returns a four * (for example a file path) and I call the function this way.
char * path; Path = get_path (); If I do not know how the length of the path will be, how will I behave? It is strictly necessary to allocate the size of the path, before the "path"
In your code:
four * path; path = Get_path (); get_path gives a string (or, of course, of the address) a string (an indicator for the string one for its first letter Is an indicator). Assignment only copy of that pointer value Script, which stores it in the path . get_path function should be allocated to keep the string in any way . There are many ways to do that. Some people make it the responsibility of the collar when space will not be required.
Recommend to read: Section 4 (Points), 6 (arrays and pointers), 7 (memory allocation), and 8 (characters and strings).
Comments
Post a Comment