I am trying to split a long format string
to fprintf()
into multiple lines using the \
character as shown below:
fprintf(stdout, "This program take a date supplied by the user in dd/mm/yyyy format...\n\
And returns the day of the week for that date using Zeller's rule.\n\n\
Enter date in (dd/mm/yyyy) format: ");
this causes whitespaces
to be added to the output as shown below:
This program take a date supplied by the user in dd/mm/yyyy format...
And returns the day of the week for that date using Zeller's rule.
Enter date in (dd/mm/yyyy) format:
this answer suggests this should work. I also checked this answer before posting here. A comment on it mentions that this approach...
...suffers from the fact that it breaks if there is any whitespace after the '\'; a bug that can be baffling when it occurs.
cat -A
's output on the program file...
^Ifprintf(stdout, "This program take a date supplied by the user in dd/mm/yyyy format...\n\$
^I^I^IAnd returns the day of the week for that date using Zeller's rule.\n\n\$
^I^I^IEnter date in (dd/mm/yyyy) format: ");$
...shows no whitespace after \
; although it does introduce <TAB>
s into the lines that follow. I am using vim
to edit my source files.
I use line continuation with \
all the time in Bash
, and was under the impression that it works similarly with fprintf()
format strings in C.
I'd like to keep my code readable and line widths reasonable. Other than splitting the long string into multiple fprintf()
.
- Is this standard behavior for
printf()/fprintf()
- Is it normal for a
vim
to my code when I do line continuation with\
? - How do I fix this issue?