I have a character array of 256 characters or char myArray[256] only the first couple actually hold any information
myArray[0] = 'H';
myArray[1] = 'E';
myArray[2] = 'L';
myArray[3] = 'L';
myArray[4] = 'O';
myArray[5] = NULL;
myArray[6] = NULL;
// etc...
I won't necessarily know exactly what is in the array, but I want to copy what is there, minus the null characters, to my buffer string string buffer
I thought the appropriate way to do this would be by doing the following:
buffer.append(myArray);
And the program would stop reading values once it encountered a nul character, but I'm not seeing that behavior. I'm seeing it copy the entirety of the array into my buffer, null characters and all. What would be the correct way to do this?
Edit: Some working code to make it easier
#include <string>
#include <iostream>
using namespace std;
int main()
{
string buffer;
char mychararray[256] = {NULL};
mychararray[0] = 'H';
mychararray[1] = 'e';
mychararray[2] = 'l';
mychararray[3] = 'l';
mychararray[4] = 'o';
buffer.append(mychararray);
cout << buffer << endl;
return 0;
}
Just realized I wasn't initializing the null properly and my original way works. Sorry to waste yall's time.
=NULLpart. Which is it?mychararrayafter index 4 not beNULLby default (this is an actual question, I'm quite inexperienced at c++)?mychararray?