Created
June 29, 2022 01:15
-
-
Save zoeisnowooze/6fadc2ee0232f5899a287549a92a4f4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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