Given two strings, for example
s1 = "Valentino Rossi" (which may contain as many spaces between the 2 words as I like)
s2 = "Vale"
I have to create a function that requests these two strings and that it outputs another one like this one: "Valentino (Vale) Rossi".
So for example if I have
s1 = "Mario Belli"
s2 = "Mar"
the returned string must be "Mario (Mar) Belli".
#include <stdio.h>
#include <string.h>
#define STR_LEN 32
char *makeNickname(char *s1, char *s2, char *s3);
int main() {
char nomeCognome[] = "Corrado Righetti";
char nickname[] = "Cora";
char nameNickname[STR_LEN];
makeNickname(nomeCognome, nickname, nameNickname);
printf("%s\n\n", nameNickname);
}
char *makeNickname(char *s1, char *s2, char *s3) {
char *p = s1, *q = s2, *k = s3;
while (*p) {
if (*p != ' ') {
*k++ = *p++;
} else {
*k++ = *p;
*k++ = '(';
while (*q) {
*k++ = *q;
q++;
}
*k++ = ')';
*k++ = *p;
while (*p == ' ') p++;
}
}
return s3;
}