Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!sri-spam!mordor!lll-tis!ames!ucbcad!ucbvax!decvax!minow From: minow@decvax.UUCP (Martin Minow) Newsgroups: comp.lang.c Subject: Re: newlines in string constants Message-ID: <167@decvax.UUCP> Date: Wed, 7-Oct-87 18:28:40 EDT Article-I.D.: decvax.167 Posted: Wed Oct 7 18:28:40 1987 Date-Received: Sat, 10-Oct-87 12:32:00 EDT References: <2669@xanth.UUCP> Reply-To: minow@decvax.UUCP (Martin Minow) Organization: Digital Eq. Corp. - Merrimack NH. Lines: 47 In article <2669@xanth.UUCP> kyle@xanth.UUCP (Kyle Jones) would like to have multi-line string constants without the annoying \n\ at the end of each line. The problem with allowing multi-line string constants without \ tags is that a missing terminating quote is discovered only when the compiler falls off the end of the file (or trips over another string). If you have more strings, you are in the amusing situation of compiling strings and "stringing" code. If you want to include a massive amount of text, you can write a simple pre-processor such as the following (untested). I used something similar to build a 10Kbyte string for an application. This caused interesting hiccoughs in the compiler. #include #define FALSE 0 #define TRUE 1 main() { int nl_pending = FALSE; int c; putchar('"'); while ((c = getchar()) != EOF) { if (nl_pending) { putchar('\\'); /* \n */ putchar('n'); putchar('\\'); /* \ to continue string */ putchar('\n'); /* end of line */ nl_pending = FALSE; } if (c == '\n') nl_pending = TRUE; else { putchar(c); } } putchar('"'); putchar('\n'); } Note, by the way, that Ansi C lets you write long strings as char foo[] = "abc" "def" "ghi"; You still have to add the \n explicitly. Martin Minow decvax!minow