Zdarec,
Chtěl bych se zeptat jak implementuju čísla do morseovky.
Děkuji
Hotová app..
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct
{
char code[6];
char chr;
} Item;
void addItem(Item* items, int i, char chr, char* code)
{
Item item;
item.chr = chr;
strcpy(item.code, code);
*(items + i) = item;
}
char* getCode(char chr, Item* items, int count)
{
int i;
for (i = 0; i < count; i++)
{
if ((items + i)->chr == chr)
return (items + i)->code;
}
return 0;
}
Item* loadItems(int* count)
{
Item items[64];
Item* ret = 0;
int i = 0;
addItem(items, i++, '0', "-----");
addItem(items, i++, '1', ".----");
addItem(items, i++, '2', "..---");
addItem(items, i++, '3', "...--");
addItem(items, i++, '4', "....-");
addItem(items, i++, '5', ".....");
addItem(items, i++, '6', "-....");
addItem(items, i++, '7', "--...");
addItem(items, i++, '8', "---..");
addItem(items, i++, '9', "----.");
addItem(items, i++, 'A', ".-");
addItem(items, i++, 'B', "-...");
addItem(items, i++, 'C', "-.-.");
addItem(items, i++, 'D', "-..");
addItem(items, i++, 'E', ".");
addItem(items, i++, 'F', "..-.");
addItem(items, i++, 'G', "--.");
addItem(items, i++, 'H', "....");
addItem(items, i++, 'I', "..");
addItem(items, i++, 'J', ".---");
addItem(items, i++, 'K', "-.-");
addItem(items, i++, 'L', ".-..");
addItem(items, i++, 'M', "--");
addItem(items, i++, 'N', "-.");
addItem(items, i++, 'O', "---");
addItem(items, i++, 'P', ".--.");
addItem(items, i++, 'Q', "--.-");
addItem(items, i++, 'R', ".-.");
addItem(items, i++, 'S', "...");
addItem(items, i++, 'T', "-");
addItem(items, i++, 'U', "..-");
addItem(items, i++, 'V', "...-");
addItem(items, i++, 'W', ".--");
addItem(items, i++, 'X', "-..-");
addItem(items, i++, 'Y', "-.--");
addItem(items, i++, 'Z', "--..");
addItem(items, i++, '?', "..--..");
addItem(items, i++, ',', "--..--");
addItem(items, i++, '!', "--...-");
addItem(items, i++, '.', ".-.-.-");
addItem(items, i++, ';', "-.-.-.");
addItem(items, i++, '/', "-..-.");
addItem(items, i++, '=', "-...-");
addItem(items, i++, '-', "-....-");
addItem(items, i++, '\t', ".----.");
addItem(items, i++, '(', "-.--.");
addItem(items, i++, ')', "-.--.-");
addItem(items, i++, '"', ".-..-.");
addItem(items, i++, ':', "---...");
addItem(items, i++, '_', "..--.-");
addItem(items, i++, '@', ".--.-.");
*count = i;
ret = (Item*)calloc(i, sizeof(Item));
memcpy(ret, items, sizeof(Item) * *count);
return ret;
}
int main()
{
int i, count;
char buffer[1024];
Item* items = loadItems(&count);
printf("Input: ");
fgets(buffer, sizeof(buffer), stdin);
for (i = 0; i < sizeof(buffer) && *(buffer + i) != '\n'; i++)
{
printf("%s ", getCode(toupper(*(buffer + i)), items, count));
}
free(items);
getchar();
return 0;
}
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku