0

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...

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by s_sridhar
0

Your code is C. This is a C++ forum.

It looks like it should do what you ask.

Does it run? Does it give the results you want? What's your question?

And, when you post code, please put it between code tags, thusly

[code]

your code goes here

[/code]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.