从C中的文件中读取文本

时间:2015-05-10 18:23:48

标签: c file

我正在尝试从C中的文件中读取文本但是我在命令提示符中没有得到任何内容。这是我的代码,请帮助我...

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    FILE *file=NULL;
    file = fopen("C:\\Users\\ylmzt_000\\Desktop\\Yeni klasör\\deneme.txt", "r");

    if(file != NULL)
    {
        printf("----------------\n");
        printf("content\n");
        printf("-----------------\n");

        int ch;
        while((ch=fgetc(file)) != EOF)
        {
            putchar(ch);
        }
        printf("\n");
        fclose(file);
    }
        return 0;
} 

2 个答案:

答案 0 :(得分:2)

如果fopen()返回NULL,则发生错误。构造一个可能包含

else部分

fprintf(stderr,&#34;无法打开&#39;%s&#39;(%s)\ n&#34;,fn,strerror(errno));

其中fn包含您的文件名。

另请参阅http://linux.die.net/man/3/fopen以获取进一步的提示。

答案 1 :(得分:0)

您的代码中没有明显的问题。问题可能与文件名包含非ASCII字符的事实有关:

public function getemployee($branch_no){
    $employees = employees::where("branch_no", $branch_no)->lists('title', 'id');
    return response()->json(['success' => true, 'employees' => $employees]);
}

尝试仅使用ASCII字符重命名目录。

相关问题