本文介绍了如何在C:\中访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了一个免费的c编译器,我正试图访问windows中的文件

目录c:\ program program \ ...但是当我发错时出错运行代码。

可能我的声明char * NAME错了。有人可以提出建议吗?

非常感谢。

Fzavat

char * NAME_SMS =" c:\\Program Files \\ \\\Palm \\Tungst \\Backup \\SmsDB.PDB" ;;


file_sms = fopen(NAME_SMS," r");

if(file_sms == NULL){

fprintf(stdout," Error opening file.\ n);

}


fclose(file_sms);


当我运行代码时,我得到错误打开文件。信息。如果我尝试使用

char * NAME_SMS =" c:\Program Files \ Palm \Tungst \ Backup \SmsDB.PDB" ;;我得到一个

编译器错误:词法:未知转义序列`\P''

I downloaded a free c-compiler and I''m trying to access a file in a windows
directory c:\program files\... but I get an error when I run the code.
Probably my declaration char* NAME is wrong. Anybody can give a suggestion?
Thanks very much.
Fzavat
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I try with
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P''

推荐答案




由于路径名中存在''''(SPACE),您的系统可能需要

来包装双引号的字符串。此外,它可能知道

''/''替代''\\''


char * NAME_SMS =" \\ \\ c:/ Program Files / Palm / Tungst / Backup / SmsDB.PDB \"" ;;


-

-ed-收到我的电子邮件:

C语言常见问题解答:

C-reference:

FAQ de fclc:



Because of the presence of '' '' (SPACE) in the path name, your system probably
requires to wrap the string by double quotes. Also, it probably knows that
''/'' is an alternative to ''\\''

char* NAME_SMS = "\"c:/Program Files/Palm/Tungst/Backup/SmsDB.PDB\"";

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/





如果那个不起作用,叫什么名字你正在使用的编译器?



If that don''t work, what is the name of the compiler you are using?



尝试char * NAME_SMS =" c:\Program Files \Palm \Tungst \ Backup \SmsDB.PDB" ;



try char *NAME_SMS="c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB";




否。这是完全错误的。



No. It''s fully wrong.


如果那不起作用,你的编译器是什么名字使用?



If that don''t work, what is the name of the compiler you are using?




任何体面的C编译器都会拒绝编译这样的代码。


-

-ed-在此处收到我的电子邮件:

C语言常见问题解答:

C-reference:

FAQ de fclc:



Any decent C compiler will refuse to compile such a code.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/


这篇关于如何在C:\中访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:43