Skip to main content
Made clear it's not string length of 96
Source Link
Arjan
  • 491
  • 1
  • 4
  • 12

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) So, the 96 bytes allow for a string of at most 95 characters, followed by the terminator. When printing, it prints the memory contents until it finds that null character.

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) When printing, it prints the memory contents until it finds that null character.

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) So, the 96 bytes allow for a string of at most 95 characters, followed by the terminator. When printing, it prints the memory contents until it finds that null character.

Removed obsolete details
Source Link
Arjan
  • 491
  • 1
  • 4
  • 12

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) When printing, it prints the memory contents until it finds that null character.

By the way, I assume

Serial.println(serial_store);

actually reads

Serial.println(serial_message);

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) When printing, it prints the memory contents until it finds that null character.

By the way, I assume

Serial.println(serial_store);

actually reads

Serial.println(serial_message);

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) When printing, it prints the memory contents until it finds that null character.

Source Link
Arjan
  • 491
  • 1
  • 4
  • 12

The zero-value, the "null character", indicates the end of the string. For strings, you allocate some maximum space, in your case 96 bytes:

char serial_message[96];

When storing variable-length strings in that, you need to indicate where the string ends. That's what the zero value does in a null-terminated string. (Note that 0 is really binary 0x00 here; it's not the ASCII character 48, 0x30.) When printing, it prints the memory contents until it finds that null character.

By the way, I assume

Serial.println(serial_store);

actually reads

Serial.println(serial_message);