#include <stdio.h>
#include <string.h>
void remove_non_common_letters(const char* word1, const char* word2, char* result) {
int idx = 0;
for (int i = 0; word1[i] != '\0'; ++i) {
if (strchr(word2, word1[i])) {
result[idx++] = word1[i];
}
}
result[idx] = '\0'; // Null-terminate the result string
}
int main() {
const char* word1 = "forest";
const char* word2 = "tor";
char result[64];
remove_non_common_letters(word1, word2, result);
printf("%s\n", result);
return 0;
}
/*
run:
ort
*/