C语言学习:读写一个字符

 

 1 #include <stdio.h>
 2 #include <io_utils.h>
 3 #include <errno.h>
 4 #include <string.h>
 5 
 6 //void ReadFile() {
 7 //  FILE *file = fopen("CMakeLists.txt", "r");
 8 //  if (file) {
 9 //
10 //    int next_char = getc(file);
11 //    while (next_char != EOF) {
12 //      putchar(next_char);
13 //      next_char = getc(file);
14 //    }
15 //    fclose(file);
16 //  } else {
17 //    PRINT_INT(errno);
18 //    puts(strerror(errno));
19 //    perror("fopen");
20 //  }
21 //}
22 
23 int main() {
24 //  while (1) {
25 //    int next_input = getchar();
26 //    if (next_input == EOF) {
27 //      break;
28 //    } else if(next_input == '\n') {
29 //      continue;
30 //    }
31 //    putchar(next_input);
32 //  }
33 
34 //  ReadFile();
35 
36   FILE *file = fopen("CMakeLists.txt", "r");
37   if (file) {
38 
39     int next_char = getc(file);
40     while (next_char != EOF) {
41       putchar(next_char);
42       next_char = getc(file);
43     }
44     fclose(file);
45   } else {
46     PRINT_INT(errno);
47     puts(strerror(errno));
48     perror("fopen");
49   }
50 
51   return 0;
52 }
View Code

 

 

 

 

 

posted @ 2023-02-12 15:35  泥古拉斯赵四  阅读(20)  评论(0编辑  收藏  举报