一.
读文件的时候,有时候是从缓存区里拿的,这个是操作系统设计的。
二.EOF
//
// main.c
// cdemo
//
// Created by liyongkai on 2021/6/6.
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char * argv[]) {
FILE *file = fopen("/Users/LYK/Desktop/cdemo/cdemo/test.txt", "r");
if (file == NULL) {
printf("打开文件失败!\n");
}
/*
char ch;
// 如果没有读到文件末尾 eof -> end of file
while (!feof(file)) {
ch = getc(file);
if (feof(file)) break;//如果读到了eof标识
printf("%c", ch);
}
*/
char ch;
while ((ch = getc(file)) != EOF) {
printf("%c", ch);
}
fclose(file);
file = NULL;
return 0;
}
网友评论