Of course, it helps if you explain WHY you think you need to use a String when you KNOW how many (maximum, at least) characters there are going to be in the String.
cipto:
thank you very much for all, especially for psppb. its solved.
I haven't tested the code fragment that psppb suggested, but it doesn't look as if it would compile, or accurately copy the string once the compilation errors were corrected.
Is there some reason why you don't simply declare your string as an initialised char array?
PeterH:
I haven't tested the code fragment that psppb suggested, but it doesn't look as if it would compile, or accurately copy the string once the compilation errors were corrected.
??? code is okay for me. What do you think is wrong?
Why you ask for help and after made you code? declare buffer as unsigned char, instead char.
You know already that you CAN'T assign to array a String (and you made also another error, Data without square)
Your original code:
cipto:
String FileMeasure="nama sucipt0";
int TempNumOne=sizeof(FileMeasure);
for (int a=0;a<=16;a++)
{ Data[a]=FileMeasure[a];
}
result ok, this code work 100% XD
Happy to know that you made with a for the same work or function toCharArray():
String FileMeasure="nama sucipt0";
int TempNumOne=sizeof(FileMeasure); // not used !!!
FileMeasure.toCharArray(Data,16); // TempNumOne instead 16
(And where is the declaration of Data? It's a vector of unsigned char ? Are you sure?
PeterH:
I haven't tested the code fragment that psppb suggested, but it doesn't look as if it would compile, or accurately copy the string once the compilation errors were corrected.
??? code is okay for me. What do you think is wrong?
Here is psppb's code which I commented on:
psppb:
string FileMeasure="Hello FILE!"
int TempNumOne=sizeof(FileMeasure)
char Filename[100];
for (int a=0;a<=TempNumOne;a++)
{
Filename[a]=FileMeasure[a];
}
The first statement uses an undeclared class string.
The first statement is not terminated by a semicolon.
The second statement is not terminated by a semicolon.
The variable TempNumOne (hey, what a meaningful name!) is set to the size of an instance of String rather than the number of characters in the string so an arbitrary number of characters is copied.
The resulting Filename array is not null terminated.
The OP still hasn't explained why they are messing around with the String class in the first place. The example is obviously contrived to show the problem, which is fine, but in the example the use of String is pointless - is it actually sensible for the real code to use the String class?