Top Document: comp.os.msdos.programmer FAQ part 3/5 Previous Document: Next Document: See reader questions & answers on this topic! - Help others by sharing your knowledge You've probably got something like the following code: char *filename = "c:\foo\bar\mumble.dat"; FILE *fptr; /*.*/ fptr = fopen(filename, "r"); The problem is that \f is a form feed, \b is a backspace, and \m is m. Whenever you want a backslash in a string constant in C, you must use two backslashes: char *filename = "c:\\foo\\bar\\mumble.dat"; This is a feature of every C compiler, because Dennis Ritchie designed C this way. It's a problem only on MS-DOS systems, because only DOS (and Atari ST/TT running TOS) uses the backslash in directory paths. But even in DOS this backslash convention applies _only_ to string constants in your source code. For file and keyboard input at run time, \ is just a normal character, so users running your program would type in file specs the same way as in DOS commands, with single \ characters. Another possibility is to code all paths in source programs with / rather than \ characters: char *filename = "c:/foo/bar/mumble.dat"; Ralf Brown writes, "All versions of the DOS kernel accept either forward or backslashes as directory separators. I tend to use this form more frequently than backslashes since it is easier to type and read." This applies to DOS function calls (and therefore to calls to the file library of every programming language), but not to DOS commands. User Contributions:Top Document: comp.os.msdos.programmer FAQ part 3/5 Previous Document: Next Document: Part1 - Part2 - Part3 - Part4 - Part5 - Single Page [ Usenet FAQs | Web FAQs | Documents | RFC Index ] Send corrections/additions to the FAQ Maintainer: jeffrey@carlyle.org (Jeffrey Carlyle)
Last Update March 27 2014 @ 02:11 PM
|
Comment about this article, ask questions, or add new information about this topic: