LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

WriteFile Function Error?

Hi, I'm not quite shure if I'm doing something wrong or if the function "WriteFile" has a problem. The problem appears if I use WriteFile twice after eachother with the same String-Variable. In the first WriteFile-Call the String-Variable contains for example 1200 bytes and then I overwrite the string with 1000 bytes and call the WriteFile-Function again. In this case, the File written is bigger than 1000 bytes, it also contains the 200 bytes that were in the string before. There is a c-File with example code attached that produces the failure.
0 Kudos
Message 1 of 3
(3,859 Views)
Off the top of my head...

When you read in the 1200 chars and then over wrote the string with 1000 chars, did you make the 1000th (or 1001st) a NULL.
When you calculate the stringlength of your string variable, it uses the first found NULL to determine end of string.

Change the char you overwrite the string with to write a NULL and see what happens.

Chris
0 Kudos
Message 2 of 3
(3,858 Views)
I already tried to explicit write a NULL at the end of the string (1000th character) but it doesn't help! The only thing that helps is to set each of the 1200 characters to NULL before overwriting...
0 Kudos
Message 3 of 3
(3,859 Views)