From: Joe Wright 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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