LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

The problem of function "CopyBytes"

I encounted a very strange problem when using the function of "CopyBytes", shown as below
....
 
CopyBytes (Pattern1, 0, LineBuffer, (PatternPosition1+16), i);
printf("%d, %s\n",i,Pattern1);
.....
 
 
The printf function will output :
13, MainsequenceA
4, XsssButtonpBOYAAAC 
 
The output of line 2 is very strange, since we have defined output size to 4, why it could be a string of "XsssButtonpBOYAAAC "??
 
I also attached my source codes, the function of CopyBytes is in Line109.
 
Thanks
Jacky
0 Kudos
Message 1 of 3
(3,088 Views)
From what I can tell, ReadLine returns the number of bytes read not including the LF character.  ReadLine also appends a NULL.  I don't think this is counted in the number of bytes read.  When you use CopyBytes, the terminating NULL is not copied.  You should add 1 to the value returned by ReadLine so that you include the NULL terminator.  Another tip is to initialize your character arrays to all NULL at the beginning. 

This:
char LineBuffer[10000]={0};
char Pattern1[1000]={0};

is better than this:
char LineBuffer[10000]="";
char Pattern1[1000]="";

as the first method initializes all values in the array to NULL but the second only initializes the first value to NULL.
----
I am the founder of CnCSoftwareSolutions. When not cleaning up baby drool, I write about test data or work on Vision, a tool for understanding your test data. Visit me at www.cncsoftwaresolutions.com
0 Kudos
Message 2 of 3
(3,078 Views)
This conversation is running in two threads.  JR has proposed a solution in the second thread.
----
I am the founder of CnCSoftwareSolutions. When not cleaning up baby drool, I write about test data or work on Vision, a tool for understanding your test data. Visit me at www.cncsoftwaresolutions.com
0 Kudos
Message 3 of 3
(3,064 Views)