Originally Posted by
Adak
Chars are just number values - you take a running average, and get the corresponding letter. Only need to put the teacher in therapy for a short while. <smile>
Yep, they're just numbers but implementation defined numbers which makes me an angry bear lol
Code:
#include <stdio.h>
static const unsigned char encoding[] = {
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122
};
#define LETTER_COUNT (sizeof encoding / sizeof encoding[0])
void averageChars(void)
{
int total = 0, count = 0;
int i;
for (i = 0; i < LETTER_COUNT; i++) {
total += i;
count++;
printf("%c %c\n", encoding[i], encoding[total/count]);
}
}
int main(void)
{
averageChars();
return 0;
}
Edit: Hmm. That coding array won't work. I really need a struct that has the encoding you want to average and also the output encoding and have an array of those structs. Oh well.