[英]reading text from file in C
I am trying read a text from file in C but I am getting nothing in command prompt.Here my code is,please help me ... 我正在尝试从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;
}
If fopen()
returns NULL, an error occured. 如果fopen()
返回NULL,则发生错误。 Construct an else
part which may contain 构造一个else
可能包含一部分
fprintf(stderr, "cannot open '%s' (%s)\\n", fn, strerror(errno)); fprintf(stderr,“无法打开'%s'(%s)\\ n”,fn,strerror(errno));
where fn
contains your filename. 其中fn
包含您的文件名。
Also see http://linux.die.net/man/3/fopen for further hints. 另请参见http://linux.die.net/man/3/fopen以获取更多提示。
There is no obvious problem in your code. 您的代码中没有明显的问题。 The problem may be related to the fact that the filename contains non-ASCII characters: 该问题可能与文件名包含非ASCII字符的事实有关:
C:\\Users\\ylmzt_000\\Desktop\\Yeni klasör\\deneme.txt
Try renaming the directory with only ASCII characters. 尝试仅使用ASCII字符重命名目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.