我们怎样才能找到给定的“文件路径”。是否有效,使用C程序? [英] How can we find that the given "file path" is valid or not, using C program?

查看:94
本文介绍了我们怎样才能找到给定的“文件路径”。是否有效,使用C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我吗?我想知道代码是如何工作的。



我尝试了什么:



char filename [MAX_PATH] =D:\\example\\test.txt;

FILE * fp;

fp = fopen_s (& fp,filename,r);



//想要检查给定路径是否正确,但没有异常。例如:filename [] =A:\\ file\\test.txt这是一条无效路径,如何知道?

Can any one help me? I want to know how really that code works.

What I have tried:

char filename[MAX_PATH] = "D:\\example\\test.txt";
FILE *fp;
fp = fopen_s(&fp, filename, "r");

// want to check the given path is correct or not with out exceptions. for eg: filename[] = "A:\\file\\test.txt" which is a invalid path, how to know that?

推荐答案

查看文档: fopen_s,_wfopen_s [ ^ ]

Look at the documentation: fopen_s, _wfopen_s[^]
Quote:

返回值

如果成功则为零;失败时的错误代码。有关这些错误代码的详细信息,请参阅errno,_doserrno,_sys_errlist和_sys_nerr。

Return Value
Zero if successful; an error code on failure. See errno, _doserrno, _sys_errlist, and _sys_nerr for more information about these error codes.



错误代码告诉您失败的原因: errno,_doserrno,_sys_errlist和_sys_nerr [ ^ ]


这篇关于我们怎样才能找到给定的“文件路径”。是否有效,使用C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆