Copy char arr in function to char arr in Main

I have a char arr in my function that I want to access in Main
So I tried to copy my arr in function to another arr in Main

In Main:
char buf4[1210];
....
SDread(file2read,buf4);

In Function:
String SDread(String filnamn,char* localcp) {
char buff3[1200];
strcpy(localcp,buff3);

It didn't work. Is there a better way to do it ?

Ha det gött
Bosse

If this is on an Uno or something similar, you exceed the maximum memory (1210 plus 1200).

Post your full code.

I have mega2560 but I think maybe my problem is still memory oriented.
Since others in forum has advised me NOT to use String …
So this was my first try to use buffer instead of String as return from my SDread function.
I was thinking this might help since it can be relative big.
But maybe it’s more inportant to get rid of the number of String items, even if relative small … ?
Probably I have to learn more on how to use buffers and get rid of the String stuff :sob:

WebServerSD2560.ino (23.7 KB)

Your buf4 is global, so SDread does not have to take a pointer (localcp) to a buffer as a parameter; you can directly manipulate buf4 in SDread.

If you want to pass the pointer (localcp) because you want to keep it flexible and might (in future) want to pass different buffers, you can directly manipulate localcp.

In both cases, there is no need for buff3.

You can start getting rid of String by replacing things like the below

  Serial.println("numoflf " + String(m));

by

  Serial.print("numoflf "); Serial.println(m);

You can make your code far easier to understand if you use decent variable names. E.g.
1)
The variable m in SDread counts number of lines; so call it something like numOfLines.
2)
buf2[25] seems to be an array with offset in the file that contain the beginning of a line; if so, why do you call it buf2 and not something like offsetTable.

Ok, that's real helpful if I can directly address buf4.
Also getting rid of the String conversans.

I hear you about the readability of my code.
Just too frustrated at the moment to deal with it.
Thanks you for reading it dispise this :slight_smile: