You can also use standered function strtok( ) .Take a char pointer and allocate it memory enough to hold the string.call strtok for tokens and append space at the last of each token and copy first token to string then concadinate others.