A: |
See, you probably want to ask what is wrong in the following code:
printf (strcat ("Hello ", "World!"));
strcat appends the second argument to the
first argument and returns the augmented first argument, but it does not
allocate any extra space for doing this task. So, if you do
strcat ("Hello ", "World!");
string "World!" will be copied over bytes which follows immidiately
after bytes "Hello " in the memory (whatever is there), which will
nearly surely cause a crash (because there is probably a part of code or other
data there). So, strcat may be used only when
the first argument is enough long buffer, like in:
char buffer[50];
strcpy (buffer, "Hello ");
strcat (buffer, "World!");
In other words, C language does not support dynamic string manipulations which is
present in some other languages like Basic, Turbo Pascal, etc.
|