Pergunta de entrevista da empresa Bloomberg

Implement a function in C that takes a string "Hey" and converts it to "[H][e][y]" with no return value

Respostas da entrevista

Sigiloso

8 de out. de 2011

#include #include #include void foo( char ** s) { int i, j, xLen; char *x; xLen = 3 * strlen(*s); x = (char *) malloc(xLen*sizeof(char) + 1); memset(x, '\0', strlen(x)+1); for (i=0, j=0; i

Sigiloso

8 de out. de 2011

This is what they were looking for: #include #include #include void stringFunc(const char* str, char* out){ int size = strlen(str); int new_size = 3*size; int i, j=0; for(i=0;i %s\n", hey, out); return 0; }

Sigiloso

23 de out. de 2011

void func (char *s) { if (NULL == s) return; int len = strlen (s); int len2 = 3 *len; if (NULL = realloc (s, (len2+1) * sizeof(char))) return; s[len2] = '\0'; while (len) { s[--len2] = ']'; s[--len2] = s[--len]; s[--len2] = '['; } }