I have some doubts about output.malloc will allocate a chunk of 20 bytes to p2 and we set that buffer with 0. In the while loop we are incrementing both p1 and p2 for copying string. After while loop complete "name" whould be copied into buffer returned by malloc but p2 will point sixth byte of buffer which contain 0.So when printf statement will execute to print string pointed by p2 it would print nothing.