I am trying to input a data file into C++ such that it will appear as 2 arrays of maximum value 100... so far, this is what I have...
void readfile(double x[], double y[], double sigma[], int * entries)
{
/* read data into x[] and y[]
fill sigma[] with 1's
determine the value of entries */
char name[40];
FILE *data;
*entries=0;
printf("Enter the name of the data file: ");
scanf("%40s",name);
if ((data=fopen(name,"r"))==NULL) {
printf("Can't open file %s.\n",name);
exit(1); // Exits program
}
// Assume data file contains 2 columns of data with no header
while (*entries<MAXDATA &&
fscanf(data,"%lf %lf",&x[*entries],&y[*entries])==2) {
sigma[*entries]=1;
(*entries)++;
}
if (fclose(data)) printf("Error in closing data file.\n");
return;
}
I am a student learning to use this program, and I could really use some help! Thanks everyone...