It's definitely a C issue. To be honest I don't understand that behaviour but I'm able to reproduce at least different outputs depending on how the text was saved or read. The text was taken from Livius initial post.
I used a C program to display the following Output:
Code: Select all
1 ~~~~~~~~~~~~~~~
[[**]]
]]**
[[**]]
[[*]]
[[]]*
[]]**
]]**
[[**]]
[[*]]
[[]]*
[]]**
]]**
[[**]]
[[*]]
[[]]*
[]]**
2 ~~~~~~~~~~~~~~~
[[**]]
]]**
[[**]]
[]]**
[[]]*
[]]**
]]**
[[*]]
[]]**
[[]]*
[]]**
]]**
[[*]]
[[*]]
[[]]*
[]]**
3 ~~~~~~~~~~~~~~~
[[**]]
]]**
[[**]]
[]]**
]]***
[]]**
]]**
[[*]]
[[*]]
[[]]*
[]]**
]]**
[[**]]
[]]**
[[]]*
[]]**
~~~~~~~~~~~~~~~~~
While in the first block the output comes line by line from an array ("lines") I used a continuous string ("all") in the second block.
In the third block I read the content out from a text file ("test.txt") (a short view into the cmd.exe file indicates that the WinAPI functions where used instead of standard C methodes).
Strange enough if you redirect the output of the program into a text file then block 1 and 2 are identical and mirror the text that was hard coded in the program unless Lf becomes CrLf (that's OK). Block 3 also mirrors the text in "test.txt" unless CrLf becomes CrCrLf (which again is the normal behaviour using
printf()).
Perhaps a bit off topic, but it might help to understand - the C code that I used:
Code: Select all
#include <windows.h>
#include <stdio.h>
int main()
{
int i = 0;
HANDLE hFile = INVALID_HANDLE_VALUE;
DWORD dwBytesRead = 0;
char buffer[1024] = {0};
const char * const lines[19] = {
"[[**]]",
"",
"[[**\b\b\b\b]]",
"[[***\b]]",
"[[***\b\b]]",
"[[***\b\b\b]]",
"[[***\b\b\b\b]]",
"",
"[[**\b\b\b\b\b]]",
"[[***\b]]",
"[[***\b\b]]",
"[[***\b\b\b]]",
"[[***\b\b\b\b]]",
"",
"[[**\b\b\b\b\b]]",
"[[***\b]]",
"[[***\b\b]]",
"[[***\b\b\b]]",
"[[***\b\b\b\b]]"
};
const char * all = "\
[[**]]\n\
\n\
[[**\b\b\b\b]]\n\
[[***\b]]\n\
[[***\b\b]]\n\
[[***\b\b\b]]\n\
[[***\b\b\b\b]]\n\
\n\
[[**\b\b\b\b\b]]\n\
[[***\b]]\n\
[[***\b\b]]\n\
[[***\b\b\b]]\n\
[[***\b\b\b\b]]\n\
\n\
[[**\b\b\b\b\b]]\n\
[[***\b]]\n\
[[***\b\b]]\n\
[[***\b\b\b]]\n\
[[***\b\b\b\b]]";
puts("\n1 ~~~~~~~~~~~~~~~");
for (; i < 19; ++i)
printf("%s\n", lines[i]);
puts("\n2 ~~~~~~~~~~~~~~~");
printf(all);
puts("\n\n3 ~~~~~~~~~~~~~~~");
hFile = CreateFile("test.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
if (ReadFile(hFile, buffer, 1023, &dwBytesRead, NULL))
{
buffer[dwBytesRead] = 0;
printf(buffer);
}
CloseHandle(hFile);
}
puts("\n\n~~~~~~~~~~~~~~~~~");
return 0;
}
For better understanding some escape sequences I used in the code:
- \b back space character
- \n new line character (actually a single Lf that becomes CrLf in the outputted stream).
- trailing \ escapes the new line in the C
code (has nothing to do with the content of the string).
Regards
aGerman