03.01.2017, 18:57
Quote:
It doesn't. This is known as buffer overflow. Retrieving a string from memory is basically saying: start reading at this address and continue reading until null (\0) is encountered. Thereby possibly extending into address space occupied by other variables if you're lucky or into address space reserved for critical processes if you're not so lucky. In the latter case the server will probably crash.
Create another array right after your existing one. Don't store anything in it. Do your strcat stuff and then print out both arrays afterwards. Although not guaranteed, it is reasonable to assume that the second array will be placed adjacent to the first one in memory, so even though you didn't explicitly store anything in the second array it will probably contain some text. |