24 lines
725 B
C
24 lines
725 B
C
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Fit a call sign on a four-character cargo tag. Default CMOC runtime. */
|
|
#include <cmoc.h>
|
|
|
|
static int setTag(char *tag, size_t capacity, const char *name)
|
|
{
|
|
size_t length = strlen(name);
|
|
if (length >= capacity)
|
|
return 0; /* Leave the previous tag intact. */
|
|
memcpy(tag, name, length + 1); /* Copy the terminating zero as well. */
|
|
return 1;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char tag[5] = "";
|
|
if (!setTag(tag, sizeof(tag), "MARS"))
|
|
return 1;
|
|
printf("TAG: %s, LETTERS: %u\n", tag, (unsigned) strlen(tag));
|
|
if (!setTag(tag, sizeof(tag), "EARTH") && strcmp(tag, "MARS") == 0)
|
|
printf("EARTH TOO LONG. KEPT %s\n", tag);
|
|
return 0;
|
|
}
|