[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua and C strings
- From: "Jeff Wise" <jwise@...>
- Date: Mon, 20 Oct 2008 08:28:09 -0500
I have some Lua code like:
output:write(name1, "\n")
output:write(name2, "\n")
output:write(acctno, "\n")
This code works just fine. I later process the resultant file with multiple
C programs, and I am having difficulty. All three writes are string values,
but the lack of a NULL character at the end seems to SOMETIMES cause grief.
I haven't figured out this C problem yet. Is it a good programming practice
to use the statement below instead of the above?
output:write(name1, "\0\n")
The C programs sometimes correctly get the string lengths and other times do
not. I haven't discovered a pattern to this failure, but my C expertise is
about the same as my Lua level. For example, if "name1" were X'6162630A0D'
(as verified with a hex editor), should this instead be X'616263000A0D'?
(This is Win/XP). If you look at the Lua-produced file with Notepad or
SCiTE, it looks as one would expect. The specific problem occurs when
"name2" is a dummy value, which I have assigned as "^??^". The C error seems
to be that "name1" and "name2" are read as a single line instead of two
distinct lines.