Mail Archives: djgpp/1996/12/15/09:41:47
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
- Raw text -