Mail Archives: djgpp/1996/12/15/18:51:02
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 -