www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/14/21:43:51

From: tomw AT tsys DOT demon DOT co DOT uk (Tom Wheeley)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: what about the "\"
Date: Sat, 14 Dec 96 03:17:35 GMT
Organization: Adventures and Diving
Lines: 33
Message-ID: <850533455snz@tsys.demon.co.uk>
References: <9612111400 DOT AA05959 AT emma DOT ruc DOT dk> <58ov83$h6l AT vse470 DOT vse DOT cz>
Reply-To: tw104 AT york DOT ac DOT uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 12 Dec, in article <58ov83$h6l AT vse470 DOT vse DOT cz>
     xholp09 AT drson DOT vse DOT cz "Pavel Holejsovsky" wrote:

> : char* str;
> : str = new char[5];
> : strcpy( str, "C:\PT" );
> 
> : and printing this gives ( C:PT  ), the "\" is stripped. when compiling the
> : programs there complains about and unknown escape char. How to do it?
> 
> 
> correct is
> strcpy( str, "C:\\PT" );
> because "\" character in string means begin-escape-char and it allows you
> putting chars like newline ("\n") and tab ("\t") into string. If you want
> backslash itself, you have to use "\\".

Of course, the proper solution is to use:

"C:/PT"

which works throughout DOS, enables you to port to Unix, and makes you look
more intelligent (imho).  However, you should be careful if you are parsing
a user-entered filename, as that may have backslashes in it.

:sb)   please send mail to <tw104 AT york DOT ac DOT uk>   http://www.york.ac.uk/~tw104/
--
#include <stdio.h>                  /* The .splitbung super .sig system! */
#include <string.h>
main(){FILE *f;int c;char s[99];puts("fav .sig: ");fgets(s,99,stdin);strtok
(s,"\n");f=fopen(s,"rb");while((c=getc(f))!=EOF)putchar(c);if(f)fclose(f);}


- Raw text -


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