NXC: FlattenVar issue?
Posted: 09 Aug 2012, 21:03
hey,
if I pass a string (!) to FlattenVar //ok, it's maybe odd, but let's follow the white rabbit....
then the string length is 1 more than originally.
e.g,
s=FlattenVar("world");
l=strlen(s); // says : 6!
if I write it on the screen, then there indeed is an additional blank behind:
more than this, if I concat strings together like
s=FlattenVar("world");
s2=StrCat("hello ",s,"!");
On the other hand, if I insert a strncpy:
strncpy(s,s,strlen(s)-1); // shorten string by 1 and terminate
s2=StrCat("hello ",s,"!");
It seems there is no final \0 string termination and/or it's filled up with white space or something? If that's correct, does one have to terminate that by oneself like
s=FlattenVar("world")+"\0";
- or do I miss something else?
if I pass a string (!) to FlattenVar //ok, it's maybe odd, but let's follow the white rabbit....
then the string length is 1 more than originally.
e.g,
s=FlattenVar("world");
l=strlen(s); // says : 6!
if I write it on the screen, then there indeed is an additional blank behind:
Code: Select all
TextOut(0,0,s+"<"); // says: world < , with a blank in between.
s=FlattenVar("world");
s2=StrCat("hello ",s,"!");
Code: Select all
TextOut(0,0,s2); // says: hello world (...lots of blanks...) ... without the final "!"
strncpy(s,s,strlen(s)-1); // shorten string by 1 and terminate
s2=StrCat("hello ",s,"!");
Code: Select all
TextOut(0,0,s2); // says correctly: hello world! (with final "!" and without any white space)
s=FlattenVar("world")+"\0";
- or do I miss something else?