delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/13/13:31:15

Date: Thu, 13 Mar 1997 13:16:05 -0500 (EST)
From: "art s. kagel IFMX x2697" <kagel AT dg1 DOT bloomberg DOT com>
To: Andy Bober <muajb2 AT uxa DOT ecn DOT bgu DOT edu>
Cc: djgpp AT delorie DOT com
Subject: Re: DJGPP inconsistencies?
In-Reply-To: <33280F93.B9B@uxa.ecn.bgu.edu>
Message-Id: <Pine.D-G.3.91.970313130515.13611C-100000@dg1>
Mime-Version: 1.0

There is nothing wrong with the original string.  \" does indeed imbed a 
quote character within a quoted string.

Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com

On Thu, 13 Mar 1997, Andy Bober wrote:

> [snip]
> > >         Also, I sometimes get random compiler "parse" errors when I include
> > > the following code in a program:
> > >
> > >         char *str;
> > >         if ( (str = getenv("DEM_PATH")) == NULL) {
> > >                 printf("\"DEM_PATH\" environment variable not set\n");
> > >                 exit(1);
> > >         }
> > >
> > >         Yet again...WHY?
> > 
> [snip]
> 
> It's your nested double quotes.  How many strings are in the printf()
> line?
> 
> Parse of printf() string:
> 
> "\"                                --- this starts and ends one null
> terminated string
> DEM_PATH\                          --- this is a syntax error
> " environment variable not set\n"  --- this starts and ends a second
> null terminated string
> 
> 
> Try the line like this:
> char *str;
> if ( (str = getenv("DEM_PATH")) == NULL) {
>     printf("'DEM_PATH' environment variable not set\n");
>     exit(1);
> }
> 
> 
> If you need to use the the backslashes as characters in the string, I
> believe they must be doubled. ( ie. "\\DEM_PATH\\ environment variable
> not set\n" )
> 
> Andy
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019