'&'
is a character literal, which is a small integer. The second argument of strcat
is a const char*
, which is a pointer to a character (more precisely, a pointer to the first character in a contiguous NUL-terminated array of char
s).
You presumably intended "&"
, which is a two-byte array.
Attempting to interpret a small integer as a pointer leads to precisely the problem indicated by the error.
If it were not for the problem reading the second argument, you might be presented with an error when strcat
attempts to modify the string pointed to by its first argument, which is const
and thus conceivably in read-only memory. (Modifying the first argument seems semantically incorrect, as well.)
If you compile with warnings enabled, you should see a warning about the types of the argument.
For this particular problem, consider the use of snprintf(res, MAX_STRING_SIZE, "%s&%s", c1, c2)
, which avoids modifying c1
and protects against buffer overflow. (You should compare the return value with MAX_STRING_SIZE
if you care about truncation.)