C
#include <string.h>
char *smash(const char **words, size_t count) {
char *res = malloc(1000);
res[0] = '\0';
for(int i=0; i<count; i++) {
strcat(res, words[i]);
if(i<count-1) strcat(res, " ");
}
return res;
}
#include <string.h>
char *smash(const char **words, size_t count) {
int len = count;
for(int i=0; i<count; i++) len += strlen(words[i]);
char* res;
res = (char*) malloc(len);
res[0] = '\0';
for(int i=0; i<count; i++) {
strcat(res, words[i]);
if(i<count-1) strcat(res, " ");
}
return res;
}
#include <string.h>
char *smash(const char **words, size_t count) {
char *res= malloc(1000);
int idx = 0;
for(int i=0; i<count; i++) {
for(int pos=0; words[i][pos]!=0; pos++) {
res[idx] = words[i][pos]; idx++;
}
if(i+1 != count) {
res[idx] = ' '; idx++;
}
}
res[idx] = 0;
return res;
}
PHP
function smash(array $words): string {
return implode(' ', $words);
}
R
smash <- function(words){
paste(words, collapse=" ")
}