Four is the number of letters in the ...: Difference between revisions
Four is the number of letters in the ... (view source)
Revision as of 07:02, 25 June 2020
, 3 years agoC - use GLib
(C - reduce memory usage) |
(C - use GLib) |
||
Line 51:
=={{header|C}}==
{{libheader|GLib}}
<lang c>#include <ctype.h>
#include <locale.h>
Line 56 ⟶ 57:
#include <stdio.h>
#include <stdint.h>
#include <
typedef uint64_t integer;
Line 115:
}
return &named_numbers[names_len - 1];
}▼
buffer->size += len;▼
}
Line 175 ⟶ 120:
size_t offset;
size_t length;
}
typedef struct word_list_tag {
} word_list;
void word_list_create(word_list* words
words->
words->
}
void word_list_destroy(word_list* words) {
words->words = NULL;▼
}
void word_list_clear(word_list* words) {
g_array_set_size(words->
}
void word_list_append(word_list* words, const char* str) {
size_t offset = words->str
size_t len = strlen(str);
word_t word;
▲}
word_t* word_list_get(word_list* words, size_t index) {
return &g_array_index(words->words, word_t, index);
▲ w->offset = offset;
}
void word_list_extend(word_list* words, const char* str) {
size_t len = strlen(str);
}
Line 258 ⟶ 193:
}
size_t count_letters(
const
size_t letters = 0;
const char* s = words->str
for (size_t i = 0, n =
if (isalpha((unsigned char)s[i]))
++letters;
Line 290 ⟶ 225:
size_t sentence_length(const word_list* words) {
size_t n = words->
if (n == 0)
return 0;
return words->str
}
Line 300 ⟶ 235:
size_t n = 201;
word_list result = { 0 };
word_list_create(&result
sentence(&result, n);
printf("Number of letters in first %'lu words in the sequence:\n", n);
Line 311 ⟶ 246:
for (n = 1000; n <= 10000000; n *= 10) {
sentence(&result, n);
const
const char* s = result.str
printf("The %'luth word is '%.*s' and has %lu letters. ", n
(int)word->length, s, count_letters(&result, n - 1));
printf("Sentence length: %'lu\n" , sentence_length(&result));
}
|