delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/13/10:36:44

From: Andy Bober <muajb2 AT uxa DOT ecn DOT bgu DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP inconsistencies?
Date: Thu, 13 Mar 1997 08:30:43 -0600
Organization: Educational Computing Network
Lines: 39
Message-ID: <33280F93.B9B@uxa.ecn.bgu.edu>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970313130930 DOT 6426F-100000 AT is>
NNTP-Posting-Host: modem15.wiu.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

[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