在C linux中打开文件

opc*_*0de 0 c linux file-io

我正在使用C打开文件进行阅读.我有这个代码:

fp = fopen("./settings.cfg","r");
if (fp != NULL)
    printf("OK");
else
    printf("ERROR");
Run Code Online (Sandbox Code Playgroud)

但我总是得到一个错误.

该文件位于可执行文件所在的文件夹中.我试过只写"settings.cfg".可能是什么问题?

pmg*_*pmg 6

尝试perror()让图书馆本身告诉你什么,如果有的话,是错的.

fp = fopen("./settings.cfg", "r");
if (fp != NULL)
    printf("OK\n");
else perror("fopen");
Run Code Online (Sandbox Code Playgroud)