char array shows empty as a whole, but i can get individual characters..
rrdbstudios
Posts: 160
Ok for example:
I am quite confused as to why this isn't working; I can use the variable watch in debug mode, but the "myString" array never changes length from 0 or shows a value.
Am I missing something major here? ..please set me straight on this, and the code above is just a representation of what my acutual code is; I am reading in xml from a weather feed and the char array is filled character by character as a parse it from a get_buffer_char command. When I got to take the entire char array and set the elements of my weather structure, for example:
I have tried numerous methods from making the char array a global variable, local_var, stack_var... I get no change. I am verifying my TKN and have tons of send_string 0's.
Thanks
local_var char myString[10]; myString = 'hello world'; send_string 0, "myString"; // nothing is printed, the output is blank for(I=1;i<=10; I++) send_string 0, "myString[I]"; // this prints out each character for(I=1;i<=10; I++){ send_string 0, "myString[I], ' ', myString"; // this prints out each character, but no full char array. }
I am quite confused as to why this isn't working; I can use the variable watch in debug mode, but the "myString" array never changes length from 0 or shows a value.
Am I missing something major here? ..please set me straight on this, and the code above is just a representation of what my acutual code is; I am reading in xml from a weather feed and the char array is filled character by character as a parse it from a get_buffer_char command. When I got to take the entire char array and set the elements of my weather structure, for example:
uWeather.ntemp = atoi(myString); // nothing ever shows
I have tried numerous methods from making the char array a global variable, local_var, stack_var... I get no change. I am verifying my TKN and have tons of send_string 0's.
Thanks
0
Comments
no change, im going to attempt a widechar just to see if it has any difference
I probably didn't describe my problem correctly, when using the example code. I unfortunately am working on two laptops, one of which is connected to a different network and I cannot copy the code, but paraphrase it.
As I said before, I am taking a buffer character at a time and adding it to a char array; if I print the char array out one character at a time, it outputs that character. If I try to output it as a single string, it doesn't show anything. I have found, if I initialize the character array with anything, it will then replace that what I initialized it with and output as a whole string.
So I ended up just doing:
local_var char myString[5];
myString = ' ';
... and then as I parse information out, I replace the blank spaces and I can print myString as a whole.
Im not totally sure why this is the case, but it fixes the problem.
Also, widechar had no effect except having to add wc to ch conversion in the send_string 0's to avoid errors and warnings.
Paul
If im following you correctly, if I set up a char array: myString[10], and then set it to myString = 'hello', it wont just print "hello " ? My assumption was that it would just have that empty space. Unlike in C, where the end of an array is \0 or most languages, no end is needed once a length is specified.
If this is the case, I find it hard to believe I've never run into this problem before over the years of doing netlinx.
Werid. Thanks for the insight!
I do things a certain way, so I don't always run into these issues, but I'm sure you could run a few tests to see exactly how Netlinx deals with strings if you want to figure out all its bugs/idiosyncracies. Its definitely different than C or Java. What happens with this code?
Paul
using the set_length_array ended up working the same as me doing myString = ' '; and then adding values and printing it. I just find it so weird I've never come across this situation.
Thank you for the info, I learn something new everyday!
I still come across idiosyncracies that I've never seen before. A few months ago I realized that if you declare the same module numerous times that has a structure in it holding all the device data, in a hold event, you can only access the first declared modules data. It took me a long time to debug that one!
Paul
should be:
myString = "'hello'"
if you ever want to assign something that's longer than one element you need to use " "
so to append to a string:
char myString[] = 'hello' //this is ok if you are initialising an array of unspecified length
myString = "myString, ' world'"
sorry that's all I can explain at the moment without more coffee
It does work in define_start though as this excerpt from the help file mentions. Personally, I think there are bugs lurking in there somewhere.
Paul