Skip to content

Instantly share code, notes, and snippets.

@zoeisnowooze
Created June 29, 2022 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoeisnowooze/6fadc2ee0232f5899a287549a92a4f4e to your computer and use it in GitHub Desktop.
Save zoeisnowooze/6fadc2ee0232f5899a287549a92a4f4e to your computer and use it in GitHub Desktop.
#include <stdio.h>
int count_letters(char *str, char *word) {
char c;
int letters = 0;
while ((c = *str++) && *word) {
if (c == *word) {
letters++;
word++;
}
}
if (!*word) {
return letters;
} else {
return 0;
}
}
int main(int argc, char **argv) {
if (argc < 2) {
return 1;
}
char *word;
int max_letters = 0;
for (int i = 2; i < argc; i++) {
int letters = count_letters(argv[1], argv[i]);
if (letters > max_letters) {
word = argv[i];
max_letters = letters;
}
}
if (max_letters > 0) {
printf("%s\n", word);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment