15,743,427 members
See more:
In declaring a structure, I went this way;
to hold item numbers like this "104101-101A", in this definition:

typedef struct modernitem_struct {
union {
struct moditem_struct {
char modgrpnum[3];
char modsubgrpnum[3];
char modhypen[1];
char moditemextn[3];
char moditemsubindtr[1];
*-->>>
} mod_struct;
struct mod_whole {
char whole_mod_item[12];
} whole_fyitem;
} w_union;
} full_mod_item;

/// a "C" structure definition...
full_mod_item moditem;

strcpy(moditem.w_union.whole.fyitem.whole_mod_item, "\0");
strcpy(moditem.w_union.whole.fyitem.whole_mod_item, "104101-101A");

The Question:

Since the "struct moditem_struct" structure hold 104101-101A in pieces,
The sum of the "struct moditem_struct" structure holds 11 characters.
And the sum of the "struct mod_whole" structure holds 12 characters.
NOW, do I need to add a character placeholder just to hold the null
character at the line indicated(*-->>>), to make 12 characters?

Thanks, for any help.

What I have tried:

It seems to work, but it's mainly question. I'm having problems around the routine it is contained in. Thanks.
Posted
Updated 7-Jun-21 20:07pm

## Solution 1

No, the struct is sized so the largest of the two structs in the union will fit.
To check, declare them all separately:
C
```#include<stdio.h>
typedef struct moditem_struct
{
char modgrpnum[3];
char modsubgrpnum[3];
char modhypen[1];
char moditemextn[3];
char moditemsubindtr[1];
} mod_struct;

typedef struct mod_whole
{
char whole_mod_item[12];
} whole_fyitem;

typedef struct modernitem_struct
{
union
{
mod_struct ms;
whole_fyitem wf;
} w_union;
} full_mod_item;

full_mod_item moditem;
mod_struct ms;
whole_fyitem wf;
int main()
{
printf("%ld\n", sizeof(mod_struct));
printf("%ld\n", sizeof(whole_fyitem));
printf("%ld\n", sizeof(full_mod_item));
return 0;
}```
And you will get "sensible" results:
```11
12
12```