You need to pass the buffer size along with the pointer.
int
ascii_to_morse(lookuptable *table,
char* morse, int morse_size,
char* ascii);
The buffer size is not necessarily the same as the current length of the string (which you can find using strlen).
The function as given above will read the ascii string (don't need to know the buffer size, so that is not passed) and writes into a buffer pointed to by morse, of size morse_size. It returns the number of bytes written (not counting the null).
Edit: Here's an implementation of this function which, while it fails to use the right values for morse code, shows how to manage the buffer:
typedef void lookuptable; // we ignore this parameter below anyway
// but using void lets us compile the code
int
ascii_to_morse(lookuptable *table,
char* morse, int morse_size,
char* ascii)
{
if (!ascii || !morse || morse_size < 1) { // check preconditions
return 0; // and handle it as appropriate
// you may wish to do something else if morse is null
// such as calculate the needed size
}
int remaining_size = morse_size;
while (*ascii) { // false when *ascii == '\0'
char* mc_for_letter = ".-"; //BUG: wrong morse code value
++ascii;
int len = strlen(mc_for_letter);
if (remaining_size <= len) { // not enough room
// 'or equal' because we must write a '\0' still
break;
}
strcpy(morse, mc_for_letter);
morse += len; // keep morse always pointing at the next location to write
remaining_size -= len;
}
*morse = '\0';
return morse_size - remaining_size;
}
// test the above function:
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;
}