Features:
In a C language program, there are many places where you need to enter data manually.
For example, you need to print a string of arrays: 0,1,2,3,4,5,6,7,8,9
The first step you need is a number on the console input. Before you can print.
General Code:
for (int i=0; i<=; i++) scanf ("%d", &a[i])
So today we're going to omit our own input, we can read the data in a file and print it out.
Example:
The following is a simple file read test program that reads data from Input.txt, saves the read data to the array a[10], and prints to the console.
The code:
#include <stdio.h>intMain () {inta[Ten]={0}; inti; FILE*fpread=fopen ("Input.txt","R"); where "R" is the expression readif(fpread==NULL) { return 0; } for(i=0;i<Ten; i++) {fscanf (Fpread,"%d",&A[i]); printf ("%d", A[i]); } printf ("\ n"); return 1; }
Run:
Attention:
The path to the TXT file for this method must match the path of the C file
C language read data from TXT file