www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/15/18:51:02

From: Joe Wright <wrightj AT exis DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: what about the "\"
Date: Sun, 15 Dec 1996 14:55:52 -0500
Organization: Alpha Solutions
Lines: 36
Message-ID: <32B457C8.4940@exis.net>
References: <9612111400 DOT AA05959 AT emma DOT ruc DOT dk> <5910ku$i59 AT s3 DOT iway DOT fr>
Reply-To: wrightj AT exis DOT net
NNTP-Posting-Host: ppp-1-7.exis.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

sherlock AT pratique DOT fr wrote:
> 
> owsim AT emma DOT ruc DOT dk (Ole Winther) wrote:
> 
> >Well some small problems
> 
> >I where trying this.
> 
> >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?
> 
> >Ole Winther
> 
> There are  two problems here:
> 
> - The character '\'  has special mening in C. You have to put it twice
> to use it in strings constants.
> 
> the line would become : strcpy(str,"c:\\PT");
> 
> - You declare an array of five characters, and the length of the
> string "C:\PT" is five characters PLUS the character '\0' needed at
> the end of the string ie SIX characters.
> strcpy will append it,  and probably will crash.
> 
> Hope this help

Is it worth pointing out that strcpy() doesn't know anything about
escapes?
It is only when you give it to printf() that things go awry.

Joe Wright

- Raw text -


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