The file has empty new lines.
"a"
""
"b"
""
"c"
File is included into the program via the following method
fputs (
#include "file"
,stdout
);
actual result:
abc
Expected result:
a
b
c
The file has empty new lines.
"a"
""
"b"
""
"c"
File is included into the program via the following method
fputs (
#include "file"
,stdout
);
actual result:
abc
Expected result:
a
b
c
C merges string literals separated by whitespace. When you write
"a"
""
"b"
""
"c"
C compiler merges them into "abc"; you cannot detect the difference between the two sources once the code is compiled.
If you want line breaks, insert them into your string literals explicitly:
"a\n"
"\n"
"b\n"
"\n"
"c"
fputs (
#include "file"
,stdout
);
is legal, but poor taste and against most coding conventions.
What happens is well explained by dashblinkenight's answer, that I won't repeat.
However, I would suggest another approach. Modify your build system (e.g. your Makefile if using GNU make) to generate a better (and prettier) file.inc which would contain complete statements, perhaps a succession of
WRITELINE("a");
WRITELINE("");
WRITELINE("b");
WRITELINE("");
then, before your #include "file.inc" add in your C file:
#define WRITELINE(Lin) do { fputs(Lin,fil); fputc('\n', fil); } while(0)
(this question has good answers explaining why I want to use do{ ... }while(0) ....)
You could generate easily such a fil.inc (perhaps from your fil, with some make rule invoking sed or something else).
PS. Actually, generating C code is a good idea.
I agree with the answer above, but you may also want to add "\r". Some systems require it. This character will be the carriage return (13). So you would place "\n\r" between characters.