
Patrick B. answered 07/16/20
Math and computer tutor/teacher
You need to be more specific about the records and data you are
trying to process. Here is how to open the file and read various data types.
You will probably have to declare a data type structure and store the records
in an array.
#include <stdio.h>
//suppose you have these variables
typedef struct _TDataRec
{
int x;
long longIntNum;
double dblAmt;
char str[25];
} *TDataRec;
struct _TDataRec array[N];
ReadFile(TDataRec A)
{
// opens the file
FILE * fptr = fopen("filename","r");
//reads the data
for (int iLoop=0; iLoop<N; iLoop++)
{
fscanf(fptr,"%d",&A[iLoop].x); // reads an integer value
fscanf(fptr,"%ld,&A[iLoop].longIntNum); // reads a long integer value
fscanf(fptr,"%lf",&A[iLoop].dblAmt); // reads a double value
fscanf(fptr,"%s",&A[iLoop].str); // reads string
// performs the calculations
//closes the file
fclose(fptr);
}