reserves a 2-byte bucket in memory. For this two work for 2 characters, it must be 3 elements in size. As Paul pointed out, a C string (note lower case 's') is built from an array of chars. One rule of C strings is that they are terminated with a null characters, '\0'. For your code to build a C string you would need to make these changes:
char myArray[3]; // Enough room for 2 characters plus the null termination character
// missing code...
for(int i = 0; i < 2; i++)
{
myArray[i] = 'e';
}
myArray[i] = '\0'; // This adds the null to your string.
The use of myString uses the C++ String class (note uppercase 'S') which is a real memory hog. While the String class is easier to use on the surface, you pay a huge price in terms of memory used with Strings. Also, you should not make direct assigned between Strings and strings.
While your code compiles to 3834 bytes, I don't think it works the way you want it to. The code below compiles to 2100 bytes and has the additional advantage that it works.
char myArray[3]; // Leave room for null
void setup()
{
int i;
Serial.begin(115200);
for(i = 0; i < 2; i++)
{
myArray[i] = 'e';
}
myArray[i] = '\0'; // Add the null
Serial.print("length of string is: ");
Serial.print(strlen(myArray));
Serial.println();
Serial.println(myArray);
}
void loop()
{
}
well because I can use many of the string functions. eg if I wanted to read a string until the end a of a line I can use Serial.readStringUntil('\n'); There seems to be a lot of support for strings functions. like stringOne.startsWith() stringOne.endsWith(). So for large portions of text it seems easier to work with.
Also when you are reading bytes individually what ever way my brain works, I fear that there will be clashes with byte commands, eg characters LF in the middle of text causing line feed. Or certain byte commands running undesirably.
Also when you say Serial.println(aString); it seems like less hassle.
So for large portions of text it seems easier to work with.
Usually, I find students who give me the "easier to work with" argument simply don't want to invest in themselves to learn a better way. Had you done your research, you'd have found Serial.readBytesUntil() which does the same thing are your readStringUntil() function, but uses a ton less memory. If you wish to bump along the String road, that's your call. However, when you start to crash into memory limits, you'll wish you had taken the time to learn C strings in the first place.
You will get along far better in here when you finally recognize that strings and String are NOT the same thing. Case matters a great deal. You keep saying one when you mean the other.
Is there a reason for that negative remark. Just to let you know there are people out there with questions. That's how people learn. Why is there an expectation that I should know everything when I m asking a question on a forum?
I was well aware of Serial.readBytesUntil(); In actual fact I previously asked a question online about reducing overhead by sending individual bytes over wifi using Serial.write instead of Serial.print. I got a response from someone saying, would you not just make things easier by using Serial.println because there is plenty of speed and memory.
If you look at the Arduino examples under strings there are lots of functions for string values that simplify things. I'm looking to use string text for my own personal reasons.
For what stupid definition of "less hassle"?
Do you think its appropriate to imply someone is stupid? There is no reason for being so negative. I m just hear asking some questions which is the purpose of a forum.
Is there a reason for that negative remark. Just to let you know there are people out there with questions.
Yes. It was made in an attempt for you to dig around for answers before you come here. If you were well aware of the readBytesUntil() function, then it was silly on your part to use the readStringUntil() as an example of how easy it is to use Strings. Most of your posts seem to illustrate pretty clearly that you don't know the difference between String and string, suggesting that your research efforts were a little lacking. I think you will find that, given evidence that you have exhausted all other venues for answers, people here will bend over backwards to help. If that evidence is lacking, the responses are more aimed at pointing you someplace to find your own answers.
I wasn't aware of the difference between String and string. I was used to using upper case String and my assumption was that it was a data type just like int, float, char and thus there was no incentive to read the reference on it. But hey guess what I v learned that its an object and not a data type which wouldn't have happened if I didn't ask this question in the first place. It only takes a little bit of consideration for people generally to be a little nicer for other peoples ignorance.