kettle 逐行读取文件_C程序逐行读取文件

kettle 逐行读取文件

Here you will get C program to read file line by line.

在这里,您将获得C程序逐行读取文件。

In below program we first open a demo file hello.txt with some text in read mode. Make sure the file is already present. Then we read the file character by character and display on screen.

在下面的程序中,我们首先打开一个演示文件hello.txt,其中的某些文本处于读取模式。 确保文件已经存在。 然后,我们逐字符读取文件并显示在屏幕上。

程序 (Program)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
   FILE *fp;
   char ch;
   fp = fopen("hello.txt","r");
   if(fp ==  NULL)
   {
       printf("File not found. \n");
   }
   else
   {
       printf("File is opening..... \n\n");
       while((ch = fgetc(fp)) != EOF )
       {
           printf("%c", ch);
       }
    }
    fclose(fp);
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main ( )
{
   FILE * fp ;
   char ch ;
   fp = fopen ( "hello.txt" , "r" ) ;
   if ( fp ==    NULL )
   {
       printf ( "File not found. \n" ) ;
   }
   else
   {
       printf ( "File is opening..... \n\n" ) ;
       while ( ( ch = fgetc ( fp ) ) != EOF )
       {
           printf ( "%c" , ch ) ;
       }
     }
     fclose ( fp ) ;
     return 0 ;
}

Output

输出量

kettle 逐行读取文件_C程序逐行读取文件

翻译自: https://www.thecrazyprogrammer.com/2018/08/c-program-to-read-file-line-by-line.html

kettle 逐行读取文件