# Read string from MEMPROG

**URL:** <https://forum.arduino.cc/t/read-string-from-memprog/1462156>\
**Category:** Programming\
**Created:** [October 4, 2026, 4:21pm UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156 "2026-10-04T16:21:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tursaba](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tursaba/32/1285396_2.png) [@tursaba](https://forum.arduino.cc/u/tursaba)\
**Post date:** [October 4, 2026, 4:21pm UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/1 "2026-10-04T16:21:02Z")

</div>

I need some help please.

Declared array:  
const char Bet\_ve[6][10] PROGMEM=  
{  
"text1","text2","text3 ","text4","text5 ",  
};

char name[8];  
name= char buffer [strlen\_P(Bet\_ve [text\_number] ) ];  
I got "Compilation error: expected primary-expression before 'char' "

Thanks.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [October 4, 2026, 4:33pm UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/2 "2026-10-04T16:33:30Z")

</div>

As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming category of the forum

Please post a small but complete sketch that illustrates your problem

---

<div class="post-metadata">

**Author:** ![van\_der\_decken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/van_der_decken/32/1006976_2.png) [@van\_der\_decken](https://forum.arduino.cc/u/van_der_decken)\
**Post date:** [October 4, 2026, 4:39pm UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/3 "2026-10-04T16:39:44Z")

</div>

> [@tursaba](#):
>
> name= char buffer [strlen\_P(Bet\_ve [text\_number] ) ];

While you omitted telling us exactly _where_ said error occurred (snipperitis strikes again!), I'll wager it's in the above line. It confuses me, and I imagine the compiler is equally confused. Could you explain just what it is you thought it would do?

---

<div class="post-metadata">

**Author:** ![BitSeeker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bitseeker/32/1241632_2.png) [@BitSeeker](https://forum.arduino.cc/u/BitSeeker)\
**Post date:** [October 4, 2026, 8:27pm UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/4 "2026-10-04T20:27:12Z")

</div>

I dare say the line below will confuse it as well...

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [October 4, 2026, 8:38pm UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/5 "2026-10-04T20:38:25Z")

</div>

"name" needs ~~an address or~~ brackets as "buffer" has brackets.

This:

```arduino
const char Bet_ve[6][10] PROGMEM = { "text1", "text2", "text3", "text4", "text5" };
char name[8];
char buffer[8];
int text_number = 3;

void setup() {
  name[text_number] = buffer[strlen_P(Bet_ve[text_number])];
}

void loop() {}

```

Yields this:

```arduino
Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

```

But this...

```arduino
const char Bet_ve[6][10] PROGMEM = { "text1", "text2", "text3", "text4", "text5" };
char name[8];
char buffer[8];
int text_number = 3;

void setup() {
  name = char buffer[strlen_P(Bet_ve[text_number])];
}

void loop() {}

```

Yields this...

```arduino
sketch_oct4a.ino:7:10: error: expected primary-expression before 'char'
   name = char buffer[strlen_P(Bet_ve[text_number])];
          ^~~~
exit status 1

Compilation error: expected primary-expression before 'char'

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [October 5, 2026, 7:49am UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/6 "2026-10-05T07:49:35Z")

</div>

> [@tursaba](#):
>
> name= char buffer [strlen\_P(Bet\_ve [text\_number] ) ];

you can't write `name = char buffer[...]`. The compiler sees `char` where it expects an expression after `=`, hence "expected primary-expression before 'char'".

Note also that `name` is a fixed-size array of 8 elements and arrays can't be assigned to with `=` in C/C++ at all ➜ you need to copy the bytes into that array if you need a RAM based copy.

```arduino
const char Bet_ve[6][10] PROGMEM = {
  "text1", "text2", "text3 ", "text4", "text5 ",
};

char name[10]; // big enough for the longest entry + null

void getText(uint8_t text_number) {
  strlcpy_P(name, (char*)Bet_ve[text_number], sizeof name);
}

```

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [October 5, 2026, 10:33am UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/7 "2026-10-05T10:33:57Z")

</div>

```arduino
  strlcpy_P(name, (char*)Bet_ve[text_number], sizeof name);

```

There is no need for the cast to char\*, Bet\_ve[text\_number] is already a const char\*.

How is name being used? Many functions, such as print(), can take a char array directly from PROGMEM, making the ram copy unnecessary.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [October 5, 2026, 10:58am UTC](https://forum.arduino.cc/t/read-string-from-memprog/1462156/8 "2026-10-05T10:58:42Z")

</div>

> [@david\_2018](#):
>
> There is no need for the cast to char\*, Bet\_ve[text\_number] is already a const char\*.

You are totally right

```arduino
const char Bet_ve[6][10] PROGMEM = {
  "text1", "text2", "text3 ", "text4", "text5 ", ""
};

char name[10];

void getText(uint8_t text_number) {
  if (text_number >= sizeof Bet_ve / sizeof Bet_ve[0]) {
    name[0] = '\0';
    return;
  }
  strlcpy_P(name, Bet_ve[text_number], sizeof name);
}

```

And yes this is just in case

> [@J-M-L](#):
>
> if you need a RAM based copy.
