Code:
char *link;
sprintf(link, "%c%06X%s%s%c", ...
You are declaring link as a pointer to an array of characters, but not initialising it to a valid value, so it will point to a random position in memory.
You should declare it like char link[100]; (replacing 100 with whatever the maximum size of a link is).