Mail Archives: djgpp/1997/03/13/13:31:15
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 -