Word wheel: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: Expanded a docstring.) |
m (Tidied up C code a bit) |
||
Line 39:
=={{header|C}}==
<lang c>#include <
#include <stdio.h>
#define MAX_WORD 80
#define LETTERS 26
inline bool is_letter(char c) { return c >= 'a' && c <= 'z'; }
inline int index(char c) { return c - 'a'; }
void word_wheel(const char* letters, char central, int min_length, FILE* dict) {
int max_count[
for (const char* p = letters; *p; ++p) {
char c = *p;
if (is_letter(c
++max_count[index(c
}
char word[MAX_WORD + 1] = { 0 };
while (fgets(word, MAX_WORD, dict)) {
int count[
for (const char* p = word; *p; ++p) {
char c = *p;
if (c == '\n') {
if (p >= word + min_length && count[index(central
printf("%s", word);
} else if (is_letter(c
int i = index(c
if (++count[i] > max_count[i]) {
break;
|