Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Why cant I open a file by its explicit path?
Why can't I open a file by its explicit path? The call
fopen("c:\newdir\file.dat", "r")
is failing.
✍: Guest
The file you actually requested--with the characters \n and \f in its name--probably doesn't exist, and isn't what you thought you were trying to open.
In character constants and string literals, the backslash \ is an escape character, giving special meaning to the character following it. In order for literal backslashes in a pathname to be passed through to fopen (or any other function) correctly, they have to be doubled, so that the first backslash in each pair quotes the second one:
fopen("c:\newdir\file.dat", "r")
Alternatively, under MS-DOS, it turns out that forward slashes are also accepted as directory separators, so you could use
fopen("c:/newdir/file.dat", "r")
(Note, by the way, that header file names mentioned in preprocessor #include directives are not string literals, so you may not have to worry about backslashes there.)
2015-04-08, 1141👍, 0💬
Popular Posts:
How To Use "IF" Statements on Multiple Conditions? - Oracle DBA FAQ - Understanding PL/SQL Language ...
How To Analyze Tables with "mysqlcheck"? - MySQL FAQs - Administrator Tools for Managing MySQL Serve...
What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void...
Which are the various programming approaches for WCF?
What CLASSPATH Settings Are Needed to Run JUnit? It doesn't matter if you run your JUnit tests from ...