.
int
ascii_to_morse(lookuptable *table,
char* morse, int morse_size,
char* ascii);
( strlen).
, , ascii ( , ) , morse, morse_size. ( ).
Edit: , , , , :
typedef void lookuptable;
int
ascii_to_morse(lookuptable *table,
char* morse, int morse_size,
char* ascii)
{
if (!ascii || !morse || morse_size < 1) {
return 0;
}
int remaining_size = morse_size;
while (*ascii) {
char* mc_for_letter = ".-";
++ascii;
int len = strlen(mc_for_letter);
if (remaining_size <= len) {
break;
}
strcpy(morse, mc_for_letter);
morse += len;
remaining_size -= len;
}
*morse = '\0';
return morse_size - remaining_size;
}
int main() {
char buf[10];
printf("%d \"%s\"\n", ascii_to_morse(0, buf, sizeof buf, "aaa"), buf);
printf("%d \"%s\"\n", ascii_to_morse(0, buf, sizeof buf, "a"), buf);
printf("%d \"%s\"\n", ascii_to_morse(0, buf, sizeof buf, "aaaaa"), buf);
return 0;
}
Roger Pate