But the man page for strcat says that it takes two char *s as arguments. How am I supposed to know to allocate things?
In general, when using pointers you _always_ have to consider memory allocation, at least to make sure that the compiler is doing it for you. If a library routine’s documentation does not explicitly mention allocation, it is usually the caller’s problem. The Synopsis section at the top of a Unix-style man page can be misleading. The code fragments presented there are closer to the function definition used by the call’s implementor than the invocation used by the caller. In particular, many routines which accept pointers (e.g. to structs or strings), are usually called with the address of some object (a struct, or an array — see questions 2.3 and 2.4.) Another common example is stat(). 3.4: I have a function that is supposed to return a string, but when it returns to its caller, the returned string is garbage. A: Make sure that the memory to which the function returns a pointer is correctly allocated. The returned pointer should be to a statically-allocated buffer, or to a buffer passe
Related Questions
- But the man page for strcat says that it takes two char *s as arguments. How am I supposed to know to allocate things?
- But the man page for strcat() says that it takes two char *s as arguments. How am I supposed to know to allocate things?
- When I go to KanjiLearn page, it takes one or two minutes before displaying the first card. Why?