Mail Archives: djgpp/1996/12/14/21:43:51
On 12 Dec, in article <58ov83$h6l AT vse470 DOT vse DOT cz>
xholp09 AT drson DOT vse DOT cz "Pavel Holejsovsky" wrote:
> : 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?
>
>
> correct is
> strcpy( str, "C:\\PT" );
> because "\" character in string means begin-escape-char and it allows you
> putting chars like newline ("\n") and tab ("\t") into string. If you want
> backslash itself, you have to use "\\".
Of course, the proper solution is to use:
"C:/PT"
which works throughout DOS, enables you to port to Unix, and makes you look
more intelligent (imho). However, you should be careful if you are parsing
a user-entered filename, as that may have backslashes in it.
:sb) please send mail to <tw104 AT york DOT ac DOT uk> http://www.york.ac.uk/~tw104/
--
#include <stdio.h> /* The .splitbung super .sig system! */
#include <string.h>
main(){FILE *f;int c;char s[99];puts("fav .sig: ");fgets(s,99,stdin);strtok
(s,"\n");f=fopen(s,"rb");while((c=getc(f))!=EOF)putchar(c);if(f)fclose(f);}
- Raw text -