How to assign a short string to a longer one

I'm struggling to understand this error message

incompatible types in assignment of 'const char [5]' to 'char [30]'

From this code

void setup() {
  // put your setup code here, to run once:
struct myID
{
  unsigned int MyNumber;
  char MyName[30];
} Me;

Me.MyNumber = 3;
Me.MyName ="Fred";
}

void loop() {
  // put your main code here, to run repeatedly:

}

As I understand it, I can declare a string of characters longer than I need and the assign any shorter string of characters to it.

What am I missing?

"=" copies a single object and an array of chars is more that one object

"Fred" refers to the location of that string (of characters) in memory. so when you write = "Fred", you're saying copy the location of "Fred" in memory to the left hand side of the "=".

you would typically use strcpy to copy the array of characters to another array of characters

you would also assign the location of a string to a pointer -- char *s = "Fred"

i would suggest to statically initialize a variable of the structure.

struct myID
{
    unsigned int MyNumber;
    char MyName[30];
};

struct myID Me = {3, "Fred" };

or

struct myID mes [] = {
    {  3, "Fred" },
    { 50, "Tom" },
    { 59, "Sue" },
};

#define N_MES   (sizeof(mes)/sizeof(MyId))

Use strcpy(Me.MyName ,"Fred");

and include the c string library

#include <string.h>

Thank you all. That makes sense. Looking for guidance, I followed the example here

https://www.arduino.cc/reference/en/language/variables/data-types/string/

Where Str6 is declared larger than needed.

All of the following are valid declarations for strings.

char Str1[15];
char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};
char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};
char Str4[] = "arduino";
char Str5[8] = "arduino";
char Str6[15] = "arduino";

Possibilities for declaring strings

Declare an array of chars without initializing it as in Str1

Declare an array of chars (with one extra char) and the compiler will add the required null character, as in Str2

Explicitly add the null character, Str3

Initialize with a string constant in quotation marks; the compiler 
will size the array to fit the string constant and a terminating null character, Str4

Initialize the array with an explicit size and string constant, Str5

Initialize the array, leaving extra space for a larger string, Str6

So that only applies when declaring the string.

All of the following are valid declarations for strings.

char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};

Declare an array of chars (with one extra char) and the compiler will add the required null character, as in Str2

Be careful with this. The compiler is only guaranteed to add the required zero if the string is declared globally or locally as static. As written, if it is simply declared local then there is no way of knowing what the final character will be.

char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};

This works (for globals) only because entries that are not explicitly initialized are initialized to zero and you explicitly set the array size to one greater than the number of initializers.

For example:

char Str2a[] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};

This does not work because the array length is set to the number of explicitly initialized entries. You end up without a null terminator.

[copde]char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};
char Str3a[] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};[/code]
This works in both cases because you explicitly include a null terminator.