Mail Archives: djgpp/1996/12/11/21:50:48
On Wed, 11 Dec 1996 15:00:40 +0100 (MET) owsim AT emma DOT ruc DOT dk (Ole Winther)
writes:
>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
>
In C\C++ you can think of the "\" as sort of an signal to the compiler to
do something. For instance when using the command:
printf("Hello World!\n\n");
You have two instances of "\n". The "\" in "\n" tells the compiler that
escape character (the signal I mentioned before) is comming up. So in
this case the "n" is the escape character that tells the
compiler/program to use a "newline."
So when your compiler said that their was an unknown escape character, it
was complaining that it didn't know what you meant by "\P" -- Which of
course is nonsense as far as the compiler is concerned.
When you need to actually use the "\" character, you have to use "\\".
So try:
strcpy( str, "C:\\PT" );
Hope this helps....
===================================================
Bruce Locke
Praxis_Beta AT Juno DOT Com
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2i
mQBtAzKrQH0AAAEDAL1IJ9mZFuOfLJfIcZvoL1UQSlgC/BA+LxoCRkBfAmC28ebR
2Spx81xYIHxXDw7muMVKYDioId2EbLDMF1svJq35Br462neDf9HRMJOFfDPThNbI
kIyQ0JGb8+S/kldEFQAFEbQiQnJ1Y2UgTG9ja2UgPEJydWNlX0xvY2tlQEp1bm8u
Q29tPg==
=XlnX
-----END PGP PUBLIC KEY BLOCK-----
- Raw text -